Skip to content

Commit

Permalink
never use flatmap on rdn
Browse files Browse the repository at this point in the history
  • Loading branch information
5HT committed Nov 4, 2024
1 parent c4c4633 commit 49a4170
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 5 additions & 0 deletions lib/services/cmp.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ defmodule CA.CMP do
case CA.ALG.lookup(oid) do
{:'id-PasswordBasedMac', _ } ->
incomingProtection = CA."ProtectedPart"(header: header, body: body)
:io.format 'protection: ~p~n', [incomingProtection]
{:ok, bin} = :"PKIXCMP-2009".encode(:'ProtectedPart', incomingProtection)
{owf,_} = CA.ALG.lookup(owfoid) # SHA-2
pbm = :application.get_env(:ca, :pbm, "0000") # DH shared secret
Expand Down Expand Up @@ -114,6 +115,10 @@ defmodule CA.CMP do
pkibody = {:cp, reply}
pkiheader = CA."PKIHeader"(sender: to, recipient: from, pvno: pvno, recipNonce: senderNonce,
transactionID: transactionID, protectionAlg: protectionAlg, messageTime: messageTime)

:logger.info 'P10CR OTP ~p~n', [cert]
:logger.info 'P10CR PKIX ~p~n', [convertOTPtoPKIX(cert)]

:ok = answer(socket, pkiheader, pkibody, validateProtection(pkiheader, pkibody, code))
:logger.info 'CP ~p~n', [senderNonce]
end
Expand Down
12 changes: 5 additions & 7 deletions lib/services/crt.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@ defmodule CA.CRT do

def subj({:rdnSequence, attrs}) do
{:rdnSequence, :lists.map(fn
[{t,oid,{:uTF8String,x}}] ->
[{t,oid,:asn1rt_nif.encode_ber_tlv({12, :erlang.iolist_to_binary(x)})}]
[{t,oid,x}] when is_list(x) ->
[{t,oid,:asn1rt_nif.encode_ber_tlv({19, :erlang.iolist_to_binary(x)})}]
[{t,oid,{:uTF8String,x}}] -> [{t,oid,:asn1rt_nif.encode_ber_tlv({12, :erlang.iolist_to_binary(x)})}]
[{t,oid,x}] when is_list(x) -> [{t,oid,:asn1rt_nif.encode_ber_tlv({19, :erlang.iolist_to_binary(x)})}]
[{t,oid,x}] -> [{t,oid,x}] end, attrs)}
end

def unsubj({:rdnSequence, attrs}) do
{:rdnSequence, :lists.flatmap(fn [{t,oid,x}] when is_binary(x) ->
{:rdnSequence, :lists.map(fn [{t,oid,x}] when is_binary(x) ->
case :asn1rt_nif.decode_ber_tlv(x) do
{{12,a},_} -> [{t,oid,{:uTF8String,a}}]
{{19,a},_} -> [{t,oid,:erlang.binary_to_list(a)}]
end
_ -> [] end, attrs)}
end
x -> x end, attrs)}
end

def extract(code, person) do
Expand Down

0 comments on commit 49a4170

Please sign in to comment.