OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/base/asn1_util.h" | 5 #include "net/base/asn1_util.h" |
6 | 6 |
7 namespace net { | 7 namespace net { |
8 | 8 |
9 namespace asn1 { | 9 namespace asn1 { |
10 | 10 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 150 |
151 bool ExtractSPKIFromDERCert(base::StringPiece cert, | 151 bool ExtractSPKIFromDERCert(base::StringPiece cert, |
152 base::StringPiece* spki_out) { | 152 base::StringPiece* spki_out) { |
153 if (!SeekToSPKI(&cert)) | 153 if (!SeekToSPKI(&cert)) |
154 return false; | 154 return false; |
155 if (!ParseElement(&cert, kSEQUENCE, spki_out, NULL)) | 155 if (!ParseElement(&cert, kSEQUENCE, spki_out, NULL)) |
156 return false; | 156 return false; |
157 return true; | 157 return true; |
158 } | 158 } |
159 | 159 |
| 160 bool ExtractSubjectPublicKeyFromSPKI(base::StringPiece spki, |
| 161 base::StringPiece* spk_out) { |
| 162 // From RFC 5280, Section 4.1 |
| 163 // SubjectPublicKeyInfo ::= SEQUENCE { |
| 164 // algorithm AlgorithmIdentifier, |
| 165 // subjectPublicKey BIT STRING } |
| 166 // |
| 167 // AlgorithmIdentifier ::= SEQUENCE { |
| 168 // algorithm OBJECT IDENTIFIER, |
| 169 // parameters ANY DEFINED BY algorithm OPTIONAL } |
| 170 |
| 171 // Step into SubjectPublicKeyInfo sequence. |
| 172 base::StringPiece spki_contents; |
| 173 if (!asn1::GetElement(&spki, asn1::kSEQUENCE, &spki_contents)) |
| 174 return false; |
| 175 |
| 176 // Step over algorithm field (a SEQUENCE). |
| 177 base::StringPiece algorithm; |
| 178 if (!asn1::GetElement(&spki_contents, asn1::kSEQUENCE, &algorithm)) |
| 179 return false; |
| 180 |
| 181 // Extract the subjectPublicKey field. |
| 182 if (!asn1::GetElement(&spki_contents, asn1::kBITSTRING, spk_out)) |
| 183 return false; |
| 184 return true; |
| 185 } |
| 186 |
| 187 |
160 bool ExtractCRLURLsFromDERCert(base::StringPiece cert, | 188 bool ExtractCRLURLsFromDERCert(base::StringPiece cert, |
161 std::vector<base::StringPiece>* urls_out) { | 189 std::vector<base::StringPiece>* urls_out) { |
162 urls_out->clear(); | 190 urls_out->clear(); |
163 std::vector<base::StringPiece> tmp_urls_out; | 191 std::vector<base::StringPiece> tmp_urls_out; |
164 | 192 |
165 if (!SeekToSPKI(&cert)) | 193 if (!SeekToSPKI(&cert)) |
166 return false; | 194 return false; |
167 | 195 |
168 // From RFC 5280, section 4.1 | 196 // From RFC 5280, section 4.1 |
169 // TBSCertificate ::= SEQUENCE { | 197 // TBSCertificate ::= SEQUENCE { |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 } | 322 } |
295 } | 323 } |
296 | 324 |
297 urls_out->swap(tmp_urls_out); | 325 urls_out->swap(tmp_urls_out); |
298 return true; | 326 return true; |
299 } | 327 } |
300 | 328 |
301 } // namespace asn1 | 329 } // namespace asn1 |
302 | 330 |
303 } // namespace net | 331 } // namespace net |
OLD | NEW |