Skip to content

Commit 150d4cb

Browse files
committed
crypto, feat: export X509Crl detailed properties.
1 parent 7d0a307 commit 150d4cb

File tree

4 files changed

+179
-1
lines changed

4 files changed

+179
-1
lines changed

fibjs/include/X509Crl.h

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class X509Crl : public X509Crl_base {
2525
virtual result_t loadFile(exlib::string filename);
2626
virtual result_t dump(bool pem, v8::Local<v8::Array>& retVal);
2727
virtual result_t clear();
28+
virtual result_t get_version(int32_t& retVal);
29+
virtual result_t get_issuer(exlib::string& retVal);
30+
virtual result_t get_serials(v8::Local<v8::Array>& retVal);
31+
virtual result_t get_thisUpdate(date_t& retVal);
32+
virtual result_t get_nextUpdate(date_t& retVal);
2833

2934
private:
3035
mbedtls_x509_crl m_crl;

fibjs/include/ifs/X509Crl.h

+84-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ class X509Crl_base : public object_base {
3131
virtual result_t loadFile(exlib::string filename) = 0;
3232
virtual result_t dump(bool pem, v8::Local<v8::Array>& retVal) = 0;
3333
virtual result_t clear() = 0;
34+
virtual result_t get_version(int32_t& retVal) = 0;
35+
virtual result_t get_issuer(exlib::string& retVal) = 0;
36+
virtual result_t get_serials(v8::Local<v8::Array>& retVal) = 0;
37+
virtual result_t get_thisUpdate(date_t& retVal) = 0;
38+
virtual result_t get_nextUpdate(date_t& retVal) = 0;
3439

3540
public:
3641
template <typename T>
@@ -42,6 +47,11 @@ class X509Crl_base : public object_base {
4247
static void s_loadFile(const v8::FunctionCallbackInfo<v8::Value>& args);
4348
static void s_dump(const v8::FunctionCallbackInfo<v8::Value>& args);
4449
static void s_clear(const v8::FunctionCallbackInfo<v8::Value>& args);
50+
static void s_get_version(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value>& args);
51+
static void s_get_issuer(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value>& args);
52+
static void s_get_serials(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value>& args);
53+
static void s_get_thisUpdate(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value>& args);
54+
static void s_get_nextUpdate(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value>& args);
4555
};
4656
}
4757

@@ -57,9 +67,17 @@ inline ClassInfo& X509Crl_base::class_info()
5767
{ "clear", s_clear, false }
5868
};
5969

70+
static ClassData::ClassProperty s_property[] = {
71+
{ "version", s_get_version, block_set, false },
72+
{ "issuer", s_get_issuer, block_set, false },
73+
{ "serials", s_get_serials, block_set, false },
74+
{ "thisUpdate", s_get_thisUpdate, block_set, false },
75+
{ "nextUpdate", s_get_nextUpdate, block_set, false }
76+
};
77+
6078
static ClassData s_cd = {
6179
"X509Crl", false, s__new, NULL,
62-
ARRAYSIZE(s_method), s_method, 0, NULL, 0, NULL, 0, NULL, NULL, NULL,
80+
ARRAYSIZE(s_method), s_method, 0, NULL, ARRAYSIZE(s_property), s_property, 0, NULL, NULL, NULL,
6381
&object_base::class_info()
6482
};
6583

@@ -165,6 +183,71 @@ inline void X509Crl_base::s_clear(const v8::FunctionCallbackInfo<v8::Value>& arg
165183

166184
METHOD_VOID();
167185
}
186+
187+
inline void X509Crl_base::s_get_version(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value>& args)
188+
{
189+
int32_t vr;
190+
191+
METHOD_NAME("X509Crl.version");
192+
METHOD_INSTANCE(X509Crl_base);
193+
PROPERTY_ENTER();
194+
195+
hr = pInst->get_version(vr);
196+
197+
METHOD_RETURN();
198+
}
199+
200+
inline void X509Crl_base::s_get_issuer(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value>& args)
201+
{
202+
exlib::string vr;
203+
204+
METHOD_NAME("X509Crl.issuer");
205+
METHOD_INSTANCE(X509Crl_base);
206+
PROPERTY_ENTER();
207+
208+
hr = pInst->get_issuer(vr);
209+
210+
METHOD_RETURN();
211+
}
212+
213+
inline void X509Crl_base::s_get_serials(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value>& args)
214+
{
215+
v8::Local<v8::Array> vr;
216+
217+
METHOD_NAME("X509Crl.serials");
218+
METHOD_INSTANCE(X509Crl_base);
219+
PROPERTY_ENTER();
220+
221+
hr = pInst->get_serials(vr);
222+
223+
METHOD_RETURN();
224+
}
225+
226+
inline void X509Crl_base::s_get_thisUpdate(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value>& args)
227+
{
228+
date_t vr;
229+
230+
METHOD_NAME("X509Crl.thisUpdate");
231+
METHOD_INSTANCE(X509Crl_base);
232+
PROPERTY_ENTER();
233+
234+
hr = pInst->get_thisUpdate(vr);
235+
236+
METHOD_RETURN();
237+
}
238+
239+
inline void X509Crl_base::s_get_nextUpdate(v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value>& args)
240+
{
241+
date_t vr;
242+
243+
METHOD_NAME("X509Crl.nextUpdate");
244+
METHOD_INSTANCE(X509Crl_base);
245+
PROPERTY_ENTER();
246+
247+
hr = pInst->get_nextUpdate(vr);
248+
249+
METHOD_RETURN();
250+
}
168251
}
169252

170253
#endif

fibjs/src/crypto/X509Crl.cpp

+75
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,79 @@ result_t X509Crl::clear()
139139
mbedtls_x509_crl_init(&m_crl);
140140
return 0;
141141
}
142+
143+
result_t X509Crl::get_version(int32_t& retVal)
144+
{
145+
retVal = m_crl.version;
146+
return 0;
147+
}
148+
149+
result_t X509Crl::get_issuer(exlib::string& retVal)
150+
{
151+
int32_t ret;
152+
exlib::string buf;
153+
154+
buf.resize(1024);
155+
156+
ret = mbedtls_x509_dn_gets(&buf[0], buf.length(), &m_crl.issuer);
157+
if (ret < 0)
158+
return CHECK_ERROR(_ssl::setError(ret));
159+
160+
buf.resize(ret);
161+
retVal = buf;
162+
163+
return 0;
164+
}
165+
166+
result_t X509Crl::get_serials(v8::Local<v8::Array>& retVal)
167+
{
168+
const mbedtls_x509_crl_entry* cur = &m_crl.entry;
169+
int32_t n = 0;
170+
exlib::string str;
171+
Isolate* isolate = holder();
172+
173+
retVal = v8::Array::New(isolate->m_isolate);
174+
str.resize(8192);
175+
176+
while (cur != NULL && cur->serial.len != 0) {
177+
int32_t ret;
178+
mbedtls_mpi serial;
179+
180+
mbedtls_mpi_init(&serial);
181+
ret = mbedtls_mpi_read_binary(&serial, cur->serial.p, cur->serial.len);
182+
if (ret != 0)
183+
return CHECK_ERROR(_ssl::setError(ret));
184+
185+
size_t sz = str.length();
186+
187+
ret = mbedtls_mpi_write_string(&serial, 10, &str[0], sz, &sz);
188+
mbedtls_mpi_free(&serial);
189+
if (ret != 0)
190+
return CHECK_ERROR(_ssl::setError(ret));
191+
192+
retVal->Set(n++, isolate->NewString(str.c_str(), (int32_t)sz - 1));
193+
194+
cur = cur->next;
195+
}
196+
197+
return 0;
198+
}
199+
200+
result_t X509Crl::get_thisUpdate(date_t& retVal)
201+
{
202+
retVal.create(m_crl.this_update.year, m_crl.this_update.mon,
203+
m_crl.this_update.day, m_crl.this_update.hour,
204+
m_crl.this_update.min, m_crl.this_update.sec, 0);
205+
206+
return 0;
207+
}
208+
209+
result_t X509Crl::get_nextUpdate(date_t& retVal)
210+
{
211+
retVal.create(m_crl.next_update.year, m_crl.next_update.mon,
212+
m_crl.next_update.day, m_crl.next_update.hour,
213+
m_crl.next_update.min, m_crl.next_update.sec, 0);
214+
215+
return 0;
216+
}
142217
}

idl/zh-cn/X509Crl.idl

+15
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,19 @@ interface X509Crl : object
4545
/*! @brief 清空已经加载的撤销证书
4646
*/
4747
clear();
48+
49+
/*! @brief 获取证书的版本 */
50+
readonly Integer version;
51+
52+
/*! @brief 获取证书颁发者的可分辨名称 */
53+
readonly String issuer;
54+
55+
/*! @brief 获取证书吊销序列号列表 */
56+
readonly Array serials;
57+
58+
/*! @brief 获取证书的本次更新时间 */
59+
readonly Date thisUpdate;
60+
61+
/*! @brief 获取证书的下次更新时间 */
62+
readonly Date nextUpdate;
4863
};

0 commit comments

Comments
 (0)