Skip to content

Instantly share code, notes, and snippets.

@ericr3r
Created March 4, 2021 19:27
Show Gist options
  • Save ericr3r/22bccfa4b9c8f9c593d761a01520cb81 to your computer and use it in GitHub Desktop.
Save ericr3r/22bccfa4b9c8f9c593d761a01520cb81 to your computer and use it in GitHub Desktop.
pkix sign
#
# Code contained in this function is under copyright as follows
#
# Copyright Ericsson AB 2008-2018. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
#
defp pkix_sign(tbs_cert, key) do
sa = otp_tbs_certificate(tbs_cert, :signature)
sig_alg = signature_algorithm(sa, :algorithm)
{digest_type, _} = :public_key.pkix_sign_types(sig_alg)
msg = :public_key.pkix_encode(:OTPTBSCertificate, tbs_cert, :otp)
signature = :crypto.sign(:ecdsa, digest_type, msg, key, [])
cert =
otp_certificate(
tbsCertificate: tbs_cert,
signatureAlgorithm: sa,
signature: signature
)
:public_key.pkix_encode(:OTPCertificate, cert, :otp)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment