@@ -10,6 +10,21 @@ register-codec [
10
10
type: 'cryptography
11
11
title: "Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile"
12
12
suffixes: [%.crt ]
13
+
14
+ get-fingerprint : function [ data [binary! ] method [word! ]] [
15
+ bin: binary data
16
+ loop 2 [
17
+ binary/read bin [
18
+ flags: UI8
19
+ length: LENGTH
20
+ ]
21
+ if any [
22
+ flags <> 48 ; 0x30 = class universal, constructed, SEQUENCE
23
+ length > length? bin/buffer
24
+ ][ return none ]
25
+ ]
26
+ checksum /part at data 5 'sha256 probe (length + 4 )
27
+ ]
13
28
decode: wrap [
14
29
*oid:
15
30
*val:
@@ -99,7 +114,7 @@ register-codec [
99
114
100
115
func [
101
116
data [binary! block! ]
102
- /local pkix version serialNumber issuer subject validity
117
+ /local pkix version serialNumber issuer subject validity der
103
118
][
104
119
try [all [
105
120
; as there seems to be no standard, the *.crt file
@@ -108,12 +123,15 @@ register-codec [
108
123
pkix/label = "CERTIFICATE"
109
124
data: pkix/binary
110
125
]]
111
- if binary? data [ data: der-codec/decode data ]
126
+
127
+ der: either binary? data [
128
+ der-codec/decode data
129
+ ][ data ]
112
130
if all [
113
- 2 = length? data
114
- 'SEQUENCE = data /1
115
- block? data /2
116
- ] [data: data /2 ]
131
+ 2 = length? der
132
+ 'SEQUENCE = der /1
133
+ block? der /2
134
+ ] [der: der /2 ]
117
135
118
136
result: object [
119
137
version:
@@ -127,10 +145,11 @@ register-codec [
127
145
issuer-id:
128
146
subject-id:
129
147
extensions:
148
+ fingerprint:
130
149
none
131
150
]
132
151
133
- parse data [
152
+ parse der [
134
153
'SEQUENCE into [
135
154
;-- version:
136
155
'CS0 into [
@@ -199,6 +218,18 @@ register-codec [
199
218
print dump-obj result
200
219
]
201
220
]
221
+ if all [
222
+ binary? data
223
+ hash: select [
224
+ sha256WithRSAEncryption sha256
225
+ sha384WithRSAEncryption sha384
226
+ sha512WithRSAEncryption sha512
227
+ md5withRSAEncryption md5
228
+ md4withRSAEncryption md4
229
+ ] result/signature/1
230
+ ][
231
+ try [result/fingerprint: get-fingerprint :data :hash ]
232
+ ]
202
233
result
203
234
]
204
235
]
0 commit comments