Skip to content

Commit

Permalink
New public_key in R18 got rid of legacy asn1 formats
Browse files Browse the repository at this point in the history
Handle both the old case (where we get lists and tuples)
and the new case (where we get binaries for everything).
  • Loading branch information
zuckschwerdt authored and arekinath committed Sep 17, 2015
1 parent bf52dcb commit 446dc02
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/esaml_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,10 @@ load_private_key(Path) ->
{ok, KeyFile} = file:read_file(Path),
[KeyEntry] = public_key:pem_decode(KeyFile),
Key = case public_key:pem_entry_decode(KeyEntry) of
#'PrivateKeyInfo'{privateKey = KeyData} ->
#'PrivateKeyInfo'{privateKey = KeyData} when is_list(KeyData) ->
public_key:der_decode('RSAPrivateKey', list_to_binary(KeyData));
#'PrivateKeyInfo'{privateKey = KeyData} when is_binary(KeyData) ->
public_key:der_decode('RSAPrivateKey', KeyData);
Other -> Other
end,
ets:insert(esaml_privkey_cache, {Path, Key}),
Expand Down
5 changes: 4 additions & 1 deletion src/xmerl_dsig.erl
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,10 @@ verify(Element, Fingerprints) ->
CertHash2 = crypto:hash(sha256, CertBin),

Cert = public_key:pkix_decode_cert(CertBin, plain),
{_, KeyBin} = Cert#'Certificate'.tbsCertificate#'TBSCertificate'.subjectPublicKeyInfo#'SubjectPublicKeyInfo'.subjectPublicKey,
KeyBin = case Cert#'Certificate'.tbsCertificate#'TBSCertificate'.subjectPublicKeyInfo#'SubjectPublicKeyInfo'.subjectPublicKey of
{_, KeyBin2} -> KeyBin2; % Public_Key 0.23
KeyBin2 -> KeyBin2 % Public_Key 1.0, i.e. Erlang/OTP 18
end,
Key = public_key:pem_entry_decode({'RSAPublicKey', KeyBin, not_encrypted}),

case public_key:verify(Data, HashFunction, Sig, Key) of
Expand Down

0 comments on commit 446dc02

Please sign in to comment.