Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
Vereign Client Library
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
Code
Vereign Client Library
Commits
d4f976f6
Commit
d4f976f6
authored
5 years ago
by
Gospodin Bodurov
Browse files
Options
Downloads
Plain Diff
Merge branch '53-optimize-transmission-of-vcard-parts' into 'master'
calc sha256 hash of parts on the client side Closes
#53
See merge request
!81
parents
07a52994
1ba0b9ec
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!81
calc sha256 hash of parts on the client side
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
javascript/src/iframe/viamapi-iframe.js
+1
-1
1 addition, 1 deletion
javascript/src/iframe/viamapi-iframe.js
javascript/src/utilities/emailUtilities.js
+49
-8
49 additions, 8 deletions
javascript/src/utilities/emailUtilities.js
with
50 additions
and
9 deletions
javascript/src/iframe/viamapi-iframe.js
+
1
−
1
View file @
d4f976f6
...
...
@@ -1539,7 +1539,7 @@ const connection = Penpal.connectToParent({
console
.
log
(
"
Text body is not passed to signVCard, its value is
"
,
{
text
:
textBody
});
}
const
count
=
prepareVCardParts
(
parts
);
const
count
=
await
prepareVCardParts
(
parts
);
if
(
count
.
textParts
===
0
)
{
return
encodeResponse
(
"
400
"
,
""
,
"
No text parts passed to signVCard
"
);
}
...
...
This diff is collapsed.
Click to expand it.
javascript/src/utilities/emailUtilities.js
+
49
−
8
View file @
d4f976f6
...
...
@@ -17,8 +17,10 @@ import {
}
from
"
./signingUtilities
"
;
import
{
byteArrayToBase64
,
stringToUtf8Base64
stringToUtf8Base64
,
stringToUtf8ByteArray
}
from
"
./stringUtilities
"
;
import
{
getCrypto
}
from
"
pkijs
"
;
export
const
SIGNATURE_CONTENT_TYPE
=
"
application/pkcs7-signature
"
;
export
const
DEFAULT_ATTACHMENT_NAME
=
"
attachment
"
;
...
...
@@ -150,14 +152,52 @@ const capitalizeFirstLetter = (s) => {
return
s
.
charAt
(
0
).
toUpperCase
()
+
s
.
slice
(
1
);
};
export
function
prepareVCardParts
(
parts
)
{
if
(
!
parts
)
{
return
;
async
function
sha256
(
array
)
{
const
cryptoLib
=
getCrypto
();
const
digestTmpBuf
=
await
cryptoLib
.
digest
({
name
:
"
SHA-256
"
},
array
);
const
digestTmpArray
=
new
Uint8Array
(
digestTmpBuf
);
return
digestTmpArray
;
}
async
function
hashBody
(
part
)
{
const
contentType
=
part
.
headers
[
"
Content-Type
"
];
const
origContentType
=
part
.
headers
[
"
Original-Content-Type
"
];
if
(
!
origContentType
&&
!
part
.
headers
[
"
Content-Type
"
].
startsWith
(
"
application/hash
"
)
&&
!
part
.
headers
[
"
Content-Type
"
].
startsWith
(
"
text/plain
"
)
&&
!
part
.
headers
[
"
Content-Type
"
].
startsWith
(
"
text/html
"
))
{
if
(
part
.
body
)
{
if
(
typeof
part
.
body
===
"
string
"
)
{
part
.
body
=
stringToUtf8ByteArray
(
part
.
body
);
}
if
(
part
.
body
instanceof
ArrayBuffer
)
{
part
.
body
=
byteArrayToBase64
(
new
Uint8Array
(
part
.
body
));
}
if
(
!
(
part
.
body
instanceof
Uint8Array
))
{
throw
new
Error
(
'
part body is neither string, nor Uint8Array, nor ArrayBuffer
'
);
// should not happen
}
if
(
contentType
)
{
part
.
headers
[
"
Original-Content-Type
"
]
=
contentType
;
}
part
.
headers
[
"
Content-Type
"
]
=
"
application/hash; algorithm=SHA-256
"
;
part
.
body
=
await
sha256
(
part
.
body
);
}
}
}
export
async
function
prepareVCardParts
(
parts
)
{
const
count
=
{
textParts
:
0
,
htmlParts
:
0
};
if
(
!
parts
)
{
return
count
;
}
for
(
const
part
of
parts
)
{
if
(
!
part
.
headers
)
{
part
.
headers
=
{
...
...
@@ -169,17 +209,18 @@ export function prepareVCardParts(parts) {
capitalizedHeaders
[
capitalizeHeaderName
(
key
)]
=
part
.
headers
[
key
];
}
part
.
headers
=
capitalizedHeaders
;
try
{
if
(
!
part
.
headers
[
"
Content-Type
"
])
{
part
.
headers
[
"
Content-Type
"
]
=
"
application/octet-stream
"
;
}
else
{
if
(
part
.
headers
[
"
Content-Type
"
].
startsWith
(
"
text/plain
"
))
{
count
.
textParts
++
;
}
else
if
(
part
.
headers
[
"
Content-Type
"
].
startsWith
(
"
text/html
"
))
{
count
.
htmlParts
++
;
}
}
catch
(
ignore
)
{
//ignore
}
}
if
(
part
.
body
)
{
await
hashBody
(
part
);
if
(
typeof
part
.
body
===
"
string
"
)
{
part
.
body
=
stringToUtf8Base64
(
part
.
body
);
}
else
...
...
@@ -193,7 +234,7 @@ export function prepareVCardParts(parts) {
}
}
if
(
part
.
parts
)
{
const
subcount
=
prepareVCardParts
(
part
.
parts
);
const
subcount
=
await
prepareVCardParts
(
part
.
parts
);
count
.
textParts
+=
subcount
.
textParts
;
count
.
htmlParts
+=
subcount
.
htmlParts
;
}
...
...
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