Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
OpenSK
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
koenigl2
OpenSK
Commits
00222a49
Unverified
Commit
00222a49
authored
5 years ago
by
Jean-Michel Picod
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #46 from jmichelp/fix-openssl
Better handling of OpenSSL generated keys.
parents
dfc06633
ed6f4080
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
build.rs
+21
-6
21 additions, 6 deletions
build.rs
with
21 additions
and
6 deletions
build.rs
+
21
−
6
View file @
00222a49
...
...
@@ -43,15 +43,30 @@ fn main() {
pkey
.check_key
()
.unwrap
();
assert_eq!
(
pkey
.group
()
.curve_name
(),
Some
(
Nid
::
X9_62_PRIME256V1
));
let
mut
priv_key
=
pkey
.private_key
()
.to_vec
();
if
priv_key
.len
()
==
33
&&
priv_key
[
0
]
==
0
{
priv_key
.remove
(
0
);
}
assert_eq!
(
priv_key
.len
(),
32
);
// Private keys generated by OpenSSL have variable size but we only handle
// constant size. Serialization is done in big endian so if the size is less
// than 32 bytes, we need to prepend with null bytes.
// If the size is 33 bytes, this means the serialized BigInt is negative.
// Any other size is invalid.
let
priv_key_hex
=
pkey
.private_key
()
.to_hex_str
()
.unwrap
();
let
priv_key_vec
=
pkey
.private_key
()
.to_vec
();
let
key_len
=
priv_key_vec
.len
();
assert!
(
key_len
<=
33
,
"Invalid private key (too big): {} ({:#?})"
,
priv_key_hex
,
priv_key_vec
,
);
// Copy OpenSSL generated key to our vec, starting from the end
let
mut
output_vec
=
[
0u8
;
32
];
let
min_key_len
=
std
::
cmp
::
min
(
key_len
,
32
);
output_vec
[
32
-
min_key_len
..
]
.copy_from_slice
(
&
priv_key_vec
[
key_len
-
min_key_len
..
]);
// Create the raw private key out of the OpenSSL data
let
mut
priv_key_bin_file
=
File
::
create
(
&
priv_key_bin_path
)
.unwrap
();
priv_key_bin_file
.write_all
(
&
priv_key
)
.unwrap
();
priv_key_bin_file
.write_all
(
&
output_vec
)
.unwrap
();
// Convert the PEM certificate to DER and extract the serial for AAGUID
let
input_pem_cert
=
include_bytes!
(
"crypto_data/opensk_cert.pem"
);
...
...
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