Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
Hubs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ar-noc
Hubs
Commits
d09a6da4
Commit
d09a6da4
authored
6 years ago
by
Greg Fodor
Browse files
Options
Downloads
Patches
Plain Diff
e2e encryption working for xfer
parent
5508945a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/utils/crypto.js
+11
-14
11 additions, 14 deletions
src/utils/crypto.js
src/utils/xfer-channel.js
+2
-2
2 additions, 2 deletions
src/utils/xfer-channel.js
with
13 additions
and
16 deletions
src/utils/crypto.js
+
11
−
14
View file @
d09a6da4
...
@@ -15,9 +15,7 @@ async function publicKeyToString(key) {
...
@@ -15,9 +15,7 @@ async function publicKeyToString(key) {
}
}
async
function
stringToPublicKey
(
s
)
{
async
function
stringToPublicKey
(
s
)
{
return
await
crypto
.
subtle
.
importKey
(
"
jwk
"
,
JSON
.
parse
(
s
),
{
name
:
"
ECDH
"
,
namedCurve
:
"
P-256
"
},
true
,
[
return
await
crypto
.
subtle
.
importKey
(
"
jwk
"
,
JSON
.
parse
(
s
),
{
name
:
"
ECDH
"
,
namedCurve
:
"
P-256
"
},
true
,
[]);
"
deriveKey
"
]);
}
}
function
stringToArrayBuffer
(
s
)
{
function
stringToArrayBuffer
(
s
)
{
...
@@ -30,7 +28,8 @@ function stringToArrayBuffer(s) {
...
@@ -30,7 +28,8 @@ function stringToArrayBuffer(s) {
return
buf
;
return
buf
;
}
}
function
arrayBufferToString
(
buf
)
{
function
arrayBufferToString
(
b
)
{
const
buf
=
new
Uint8Array
(
b
);
let
s
=
""
;
let
s
=
""
;
for
(
let
i
=
0
;
i
<
buf
.
byteLength
;
i
++
)
{
for
(
let
i
=
0
;
i
<
buf
.
byteLength
;
i
++
)
{
...
@@ -56,8 +55,11 @@ export async function generatePublicKeyAndEncryptedObject(incomingPublicKeyStrin
...
@@ -56,8 +55,11 @@ export async function generatePublicKeyAndEncryptedObject(incomingPublicKeyStrin
const
keyPair
=
await
crypto
.
subtle
.
generateKey
({
name
:
"
ECDH
"
,
namedCurve
:
"
P-256
"
},
true
,
[
"
deriveKey
"
]);
const
keyPair
=
await
crypto
.
subtle
.
generateKey
({
name
:
"
ECDH
"
,
namedCurve
:
"
P-256
"
},
true
,
[
"
deriveKey
"
]);
const
publicKeyString
=
await
publicKeyToString
(
keyPair
.
publicKey
);
const
publicKeyString
=
await
publicKeyToString
(
keyPair
.
publicKey
);
const
secret
=
await
deriveKey
(
keyPair
.
privateKey
,
incomingPublicKey
);
const
secret
=
await
deriveKey
(
keyPair
.
privateKey
,
incomingPublicKey
);
const
encryptedData
=
btoa
(
const
encryptedData
=
btoa
(
await
crypto
.
subtle
.
encrypt
({
name
:
"
AES-CBC
"
,
iv
},
secret
,
stringToArrayBuffer
(
JSON
.
stringify
(
obj
)))
arrayBufferToString
(
await
crypto
.
subtle
.
encrypt
({
name
:
"
AES-CBC
"
,
iv
},
secret
,
stringToArrayBuffer
(
JSON
.
stringify
(
obj
)))
)
);
);
return
{
publicKeyString
,
encryptedData
};
return
{
publicKeyString
,
encryptedData
};
...
@@ -66,14 +68,9 @@ export async function generatePublicKeyAndEncryptedObject(incomingPublicKeyStrin
...
@@ -66,14 +68,9 @@ export async function generatePublicKeyAndEncryptedObject(incomingPublicKeyStrin
// Requestor then takes the receiver's public key, the private key (returned from generateKeys()), and the data from the receiver.
// Requestor then takes the receiver's public key, the private key (returned from generateKeys()), and the data from the receiver.
export
async
function
decryptObject
(
publicKeyString
,
privateKey
,
base64value
)
{
export
async
function
decryptObject
(
publicKeyString
,
privateKey
,
base64value
)
{
const
iv
=
new
Uint8Array
(
16
);
const
iv
=
new
Uint8Array
(
16
);
const
publicKey
=
await
publicKeyToString
(
publicKeyString
);
const
publicKey
=
await
stringToPublicKey
(
publicKeyString
);
const
secret
=
await
deriveKey
(
privateKey
,
publicKey
);
const
secret
=
await
deriveKey
(
privateKey
,
publicKey
);
const
ciphertext
=
stringToArrayBuffer
(
atob
(
base64value
));
return
JSON
.
parse
(
const
data
=
await
crypto
.
subtle
.
decrypt
({
name
:
"
AES-CBC
"
,
iv
},
secret
,
ciphertext
);
arrayBufferToString
(
return
JSON
.
parse
(
arrayBufferToString
(
data
));
new
Uint8Array
(
await
crypto
.
subtle
.
decrypt
({
name
:
"
AES-CBC
"
,
iv
},
secret
,
stringToArrayBuffer
(
atob
(
base64value
)))
)
)
);
}
}
This diff is collapsed.
Click to expand it.
src/utils/xfer-channel.js
+
2
−
2
View file @
d09a6da4
...
@@ -55,7 +55,7 @@ export default class XferChannel {
...
@@ -55,7 +55,7 @@ export default class XferChannel {
data
.
profile
=
{
...
this
.
store
.
state
.
profile
};
data
.
profile
=
{
...
this
.
store
.
state
.
profile
};
}
}
this
.
generatePublicKeyAndEncryptedObject
(
incoming
.
public_key
).
then
(
generatePublicKeyAndEncryptedObject
(
incoming
.
public_key
,
data
).
then
(
({
publicKeyString
,
encryptedData
})
=>
{
({
publicKeyString
,
encryptedData
})
=>
{
const
payload
=
{
const
payload
=
{
target_session_id
:
incoming
.
reply_to_session_id
,
target_session_id
:
incoming
.
reply_to_session_id
,
...
@@ -118,7 +118,7 @@ export default class XferChannel {
...
@@ -118,7 +118,7 @@ export default class XferChannel {
finished
=
true
;
finished
=
true
;
channel
.
leave
();
channel
.
leave
();
this
.
decryptObject
(
payload
.
public_key
,
privateKey
,
payload
.
data
).
then
(
resolve
);
decryptObject
(
payload
.
public_key
,
privateKey
,
payload
.
data
).
then
(
resolve
);
});
});
channel
.
join
().
receive
(
"
error
"
,
r
=>
console
.
error
(
r
));
channel
.
join
().
receive
(
"
error
"
,
r
=>
console
.
error
(
r
));
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment