| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 |
| 15 | #include <stdio.h> |
| 16 | #include <string.h> |
| 17 |
| 18 | #include <openssl/asn1.h> |
| 19 | #include <openssl/conf.h> |
| 20 | #include <openssl/err.h> |
| 21 | #include <openssl/mem.h> |
| 22 | #include <openssl/obj.h> |
| 23 | #include <openssl/x509.h> |
| 24 |
| 25 | #include "../internal.h" |
| 26 | #include "ext_dat.h" |
| 27 |
| 28 |
| 29 | static char *i2s_ASN1_IA5STRING(const X509V3_EXT_METHOD *method, void *ext) { |
| 30 | const ASN1_IA5STRING *ia5 = reinterpret_cast<const ASN1_IA5STRING *>(ext); |
| 31 | char *tmp; |
| 32 | if (!ia5 || !ia5->length) { |
| 33 | return NULL; |
| 34 | } |
| 35 | if (!(tmp = reinterpret_cast<char *>(OPENSSL_malloc(ia5->length + 1)))) { |
| 36 | return NULL; |
| 37 | } |
| 38 | OPENSSL_memcpy(tmp, ia5->data, ia5->length); |
| 39 | tmp[ia5->length] = 0; |
| 40 | return tmp; |
| 41 | } |
| 42 |
| 43 | static void *s2i_ASN1_IA5STRING(const X509V3_EXT_METHOD *method, |
| 44 | const X509V3_CTX *ctx, const char *str) { |
| 45 | ASN1_IA5STRING *ia5; |
| 46 | if (!str) { |
| 47 | OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_NULL_ARGUMENT); |
| 48 | return NULL; |
| 49 | } |
| 50 | if (!(ia5 = ASN1_IA5STRING_new())) { |
| 51 | goto err; |
| 52 | } |
| 53 | if (!ASN1_STRING_set(ia5, str, strlen(str))) { |
| 54 | ASN1_IA5STRING_free(ia5); |
| 55 | goto err; |
| 56 | } |
| 57 | return ia5; |
| 58 | err: |
| 59 | return NULL; |
| 60 | } |
| 61 |
| 62 | #define EXT_IA5STRING(nid) \ |
| 63 | { \ |
| 64 | nid, 0, ASN1_ITEM_ref(ASN1_IA5STRING), 0, 0, 0, 0, i2s_ASN1_IA5STRING, \ |
| 65 | s2i_ASN1_IA5STRING, 0, 0, 0, 0, NULL \ |
| 66 | } |
| 67 |
| 68 | #define EXT_END \ |
| 69 | { -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } |
| 70 |
| 71 | const X509V3_EXT_METHOD v3_ns_ia5_list[] = { |
| 72 | EXT_IA5STRING(NID_netscape_base_url), |
| 73 | EXT_IA5STRING(NID_netscape_revocation_url), |
| 74 | EXT_IA5STRING(NID_netscape_ca_revocation_url), |
| 75 | EXT_IA5STRING(NID_netscape_renewal_url), |
| 76 | EXT_IA5STRING(NID_netscape_ca_policy_url), |
| 77 | EXT_IA5STRING(NID_netscape_ssl_server_name), |
| 78 | EXT_IA5STRING(NID_netscape_comment), |
| 79 | EXT_END}; |
| 80 |