69 } |
69 } |
70 lua_replace(L, -2); /* Replace key with table */ |
70 lua_replace(L, -2); /* Replace key with table */ |
71 return 0; |
71 return 0; |
72 } |
72 } |
73 |
73 |
74 int meth_decode(lua_State* L) |
74 int meth_subject(lua_State* L) |
75 { |
75 { |
76 X509 *peer; |
76 X509 *peer; |
77 X509_NAME *subject; |
77 X509_NAME *subject; |
78 int i, j, n_entries; |
78 int i, n_entries; |
79 |
79 |
80 peer = luasec_to_x509(L, 1); |
80 peer = luasec_to_x509(L, 1); |
81 |
81 |
82 lua_newtable(L); /* ret */ |
82 lua_newtable(L); /* ret */ |
83 |
83 |
84 subject = X509_get_subject_name(peer); |
84 subject = X509_get_subject_name(peer); |
85 |
|
86 n_entries = X509_NAME_entry_count(subject); |
85 n_entries = X509_NAME_entry_count(subject); |
87 |
86 |
88 lua_newtable(L); /* {} */ |
|
89 lua_pushvalue(L, -1); |
|
90 lua_setfield(L, -3, "subject"); /* ret.subject = {} */ |
|
91 for(i = 0; i <= n_entries; i++) |
87 for(i = 0; i <= n_entries; i++) |
92 { |
88 { |
93 X509_NAME_ENTRY *entry; |
89 X509_NAME_ENTRY *entry; |
94 ASN1_OBJECT *object; |
90 ASN1_OBJECT *object; |
95 |
91 |
96 entry = X509_NAME_get_entry(subject, i); |
92 entry = X509_NAME_get_entry(subject, i); |
97 object = X509_NAME_ENTRY_get_object(entry); |
93 object = X509_NAME_ENTRY_get_object(entry); |
98 |
94 |
|
95 lua_newtable(L); |
|
96 |
99 luasec_push_asn1_objname(L, object, 1); |
97 luasec_push_asn1_objname(L, object, 1); |
100 |
98 lua_setfield(L, -2, "oid"); |
101 if(luasec_push_subtable(L, -2)) |
99 |
102 { |
100 luasec_push_asn1_objname(L, object, 0); |
103 /* Get short/long name of the entry */ |
101 lua_setfield(L, -2, "name"); |
104 luasec_push_asn1_objname(L, object, 0); |
|
105 lua_setfield(L, -2, "name"); |
|
106 } |
|
107 |
102 |
108 luasec_push_asn1_string(L, X509_NAME_ENTRY_get_data(entry)); |
103 luasec_push_asn1_string(L, X509_NAME_ENTRY_get_data(entry)); |
|
104 lua_setfield(L, -2, "value"); |
|
105 |
109 lua_rawseti(L, -2, lua_objlen(L, -2)+1); |
106 lua_rawseti(L, -2, lua_objlen(L, -2)+1); |
110 |
107 |
111 lua_pop(L, 1); |
108 } |
112 } |
109 return 1; |
113 |
110 } |
114 lua_pop(L, 1); /* ret.subject */ |
111 |
115 |
112 int meth_extensions(lua_State* L) |
116 lua_newtable(L); /* {} */ |
113 { |
117 lua_pushvalue(L, -1); |
114 X509 *peer; |
118 lua_setfield(L, -3, "extensions"); /* ret.extensions = {} */ |
115 int i, j; |
|
116 |
|
117 peer = luasec_to_x509(L, 1); |
|
118 |
|
119 lua_newtable(L); /* ret */ |
119 |
120 |
120 i = -1; |
121 i = -1; |
121 while((i = X509_get_ext_by_NID(peer, NID_subject_alt_name, i)) != -1) |
122 while((i = X509_get_ext_by_NID(peer, NID_subject_alt_name, i)) != -1) |
122 { |
123 { |
123 X509_EXTENSION *extension; |
124 X509_EXTENSION *extension; |
130 |
131 |
131 values = X509V3_EXT_d2i(extension); |
132 values = X509V3_EXT_d2i(extension); |
132 if(values == NULL) |
133 if(values == NULL) |
133 break; |
134 break; |
134 |
135 |
135 /* Push ret.extensions[oid] */ |
136 /* Push ret[oid] */ |
136 luasec_push_asn1_objname(L, extension->object, 1); |
137 luasec_push_asn1_objname(L, extension->object, 1); |
137 luasec_push_subtable(L, -2); |
138 luasec_push_subtable(L, -2); |
138 /* Set ret.extensions[oid].name = name */ |
139 /* Set ret[oid].name = name */ |
139 luasec_push_asn1_objname(L, extension->object, 0); |
140 luasec_push_asn1_objname(L, extension->object, 0); |
140 lua_setfield(L, -2, "name"); |
141 lua_setfield(L, -2, "name"); |
141 |
142 |
142 n_general_names = sk_GENERAL_NAME_num(values); |
143 n_general_names = sk_GENERAL_NAME_num(values); |
143 for(j = 0; j < n_general_names; j++) |
144 for(j = 0; j < n_general_names; j++) |