diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/openssl.c | 93 |
1 files changed, 60 insertions, 33 deletions
diff --git a/src/openssl.c b/src/openssl.c index 84d8079..15749c9 100644 --- a/src/openssl.c +++ b/src/openssl.c | |||
@@ -1498,15 +1498,16 @@ static int gn_setCritical(lua_State *L) { | |||
1498 | 1498 | ||
1499 | static int gn_checktype(lua_State *L, int index) { | 1499 | static int gn_checktype(lua_State *L, int index) { |
1500 | static const struct { int type; const char *name; } table[] = { | 1500 | static const struct { int type; const char *name; } table[] = { |
1501 | { GEN_EMAIL, "RFC822Name" }, | 1501 | { GEN_EMAIL, "RFC822Name" }, |
1502 | { GEN_EMAIL, "RFC822" }, | 1502 | { GEN_EMAIL, "RFC822" }, |
1503 | { GEN_EMAIL, "email" }, | 1503 | { GEN_EMAIL, "email" }, |
1504 | { GEN_URI, "UniformResourceIdentifier" }, | 1504 | { GEN_URI, "UniformResourceIdentifier" }, |
1505 | { GEN_URI, "URI" }, | 1505 | { GEN_URI, "URI" }, |
1506 | { GEN_DNS, "DNSName" }, | 1506 | { GEN_DNS, "DNSName" }, |
1507 | { GEN_DNS, "DNS" }, | 1507 | { GEN_DNS, "DNS" }, |
1508 | { GEN_IPADD, "IPAddress" }, | 1508 | { GEN_IPADD, "IPAddress" }, |
1509 | { GEN_IPADD, "IP" }, | 1509 | { GEN_IPADD, "IP" }, |
1510 | { GEN_DIRNAME, "DirName" }, | ||
1510 | }; | 1511 | }; |
1511 | const char *type = luaL_checkstring(L, index); | 1512 | const char *type = luaL_checkstring(L, index); |
1512 | unsigned i; | 1513 | unsigned i; |
@@ -1523,12 +1524,28 @@ static int gn_checktype(lua_State *L, int index) { | |||
1523 | static int gn_add(lua_State *L) { | 1524 | static int gn_add(lua_State *L) { |
1524 | GENERAL_NAMES *gens = checksimple(L, 1, X509_GENS_CLASS); | 1525 | GENERAL_NAMES *gens = checksimple(L, 1, X509_GENS_CLASS); |
1525 | int type = gn_checktype(L, 2); | 1526 | int type = gn_checktype(L, 2); |
1527 | X509_NAME *name; | ||
1526 | size_t len; | 1528 | size_t len; |
1527 | const char *txt = luaL_checklstring(L, 3, &len); | 1529 | const char *txt; |
1528 | GENERAL_NAME *gen = NULL; | 1530 | GENERAL_NAME *gen = NULL; |
1529 | union { struct in6_addr in6; struct in_addr in; } ip; | 1531 | union { struct in6_addr in6; struct in_addr in; } ip; |
1530 | 1532 | ||
1531 | if (type == GEN_IPADD) { | 1533 | switch (type) { |
1534 | case GEN_DIRNAME: | ||
1535 | name = checksimple(L, 3, X509_NAME_CLASS); | ||
1536 | |||
1537 | if (!(gen = GENERAL_NAME_new())) | ||
1538 | goto error; | ||
1539 | |||
1540 | gen->type = type; | ||
1541 | |||
1542 | if (!(gen->d.dirn = X509_NAME_dup(name))) | ||
1543 | goto error; | ||
1544 | |||
1545 | break; | ||
1546 | case GEN_IPADD: | ||
1547 | txt = luaL_checkstring(L, 3); | ||
1548 | |||
1532 | if (strchr(txt, ':')) { | 1549 | if (strchr(txt, ':')) { |
1533 | if (1 != inet_pton(AF_INET6, txt, &ip.in6)) | 1550 | if (1 != inet_pton(AF_INET6, txt, &ip.in6)) |
1534 | return luaL_error(L, "%s: invalid address", txt); | 1551 | return luaL_error(L, "%s: invalid address", txt); |
@@ -1542,18 +1559,23 @@ static int gn_add(lua_State *L) { | |||
1542 | txt = (char *)&ip.in.s_addr; | 1559 | txt = (char *)&ip.in.s_addr; |
1543 | len = 4; | 1560 | len = 4; |
1544 | } | 1561 | } |
1545 | } | ||
1546 | 1562 | ||
1547 | if (!(gen = GENERAL_NAME_new())) | 1563 | goto text; |
1548 | goto error; | 1564 | default: |
1565 | txt = luaL_checklstring(L, 3, &len); | ||
1566 | text: | ||
1567 | if (!(gen = GENERAL_NAME_new())) | ||
1568 | goto error; | ||
1549 | 1569 | ||
1550 | gen->type = type; | 1570 | gen->type = type; |
1551 | 1571 | ||
1552 | if (!(gen->d.ia5 = M_ASN1_IA5STRING_new())) | 1572 | if (!(gen->d.ia5 = M_ASN1_IA5STRING_new())) |
1553 | goto error; | 1573 | goto error; |
1554 | 1574 | ||
1555 | if (!ASN1_STRING_set(gen->d.ia5, (unsigned char *)txt, len)) | 1575 | if (!ASN1_STRING_set(gen->d.ia5, (unsigned char *)txt, len)) |
1556 | goto error; | 1576 | goto error; |
1577 | break; | ||
1578 | } /* switch() */ | ||
1557 | 1579 | ||
1558 | sk_GENERAL_NAME_push(gens, gen); | 1580 | sk_GENERAL_NAME_push(gens, gen); |
1559 | 1581 | ||
@@ -1567,6 +1589,9 @@ error: | |||
1567 | } /* gn_add() */ | 1589 | } /* gn_add() */ |
1568 | 1590 | ||
1569 | 1591 | ||
1592 | #define GN_PUSHSTRING(L, o) \ | ||
1593 | lua_pushlstring((L), (char *)M_ASN1_STRING_data((o)), M_ASN1_STRING_length((o))) | ||
1594 | |||
1570 | static int gn__next(lua_State *L) { | 1595 | static int gn__next(lua_State *L) { |
1571 | GENERAL_NAMES *gens = checksimple(L, lua_upvalueindex(1), X509_GENS_CLASS); | 1596 | GENERAL_NAMES *gens = checksimple(L, lua_upvalueindex(1), X509_GENS_CLASS); |
1572 | int i = lua_tointeger(L, lua_upvalueindex(2)); | 1597 | int i = lua_tointeger(L, lua_upvalueindex(2)); |
@@ -1587,21 +1612,18 @@ static int gn__next(lua_State *L) { | |||
1587 | 1612 | ||
1588 | switch (name->type) { | 1613 | switch (name->type) { |
1589 | case GEN_EMAIL: | 1614 | case GEN_EMAIL: |
1590 | tag = "email"; | 1615 | lua_pushstring(L, "email"); |
1591 | txt = (char *)M_ASN1_STRING_data(name->d.rfc822Name); | 1616 | GN_PUSHSTRING(L, name->d.rfc822Name); |
1592 | len = M_ASN1_STRING_length(name->d.rfc822Name); | ||
1593 | 1617 | ||
1594 | break; | 1618 | break; |
1595 | case GEN_URI: | 1619 | case GEN_URI: |
1596 | tag = "URI"; | 1620 | lua_pushstring(L, "URI"); |
1597 | txt = (char *)M_ASN1_STRING_data(name->d.uniformResourceIdentifier); | 1621 | GN_PUSHSTRING(L, name->d.uniformResourceIdentifier); |
1598 | len = M_ASN1_STRING_length(name->d.uniformResourceIdentifier); | ||
1599 | 1622 | ||
1600 | break; | 1623 | break; |
1601 | case GEN_DNS: | 1624 | case GEN_DNS: |
1602 | tag = "DNS"; | 1625 | lua_pushstring(L, "DNS"); |
1603 | txt = (char *)M_ASN1_STRING_data(name->d.dNSName); | 1626 | GN_PUSHSTRING(L, name->d.dNSName); |
1604 | len = M_ASN1_STRING_length(name->d.dNSName); | ||
1605 | 1627 | ||
1606 | break; | 1628 | break; |
1607 | case GEN_IPADD: | 1629 | case GEN_IPADD: |
@@ -1629,16 +1651,21 @@ static int gn__next(lua_State *L) { | |||
1629 | 1651 | ||
1630 | len = strlen(txt); | 1652 | len = strlen(txt); |
1631 | 1653 | ||
1654 | lua_pushstring(L, "IP"); | ||
1655 | lua_pushlstring(L, txt, len); | ||
1656 | |||
1657 | break; | ||
1658 | case GEN_DIRNAME: | ||
1659 | lua_pushstring(L, "DirName"); | ||
1660 | xn_dup(L, name->d.dirn); | ||
1661 | |||
1632 | break; | 1662 | break; |
1633 | default: | 1663 | default: |
1634 | continue; | 1664 | continue; |
1635 | } | 1665 | } /* switch() */ |
1636 | |||
1637 | lua_pushstring(L, tag); | ||
1638 | lua_pushlstring(L, txt, len); | ||
1639 | 1666 | ||
1640 | break; | 1667 | break; |
1641 | } | 1668 | } /* while() */ |
1642 | 1669 | ||
1643 | lua_pushinteger(L, i); | 1670 | lua_pushinteger(L, i); |
1644 | lua_replace(L, lua_upvalueindex(2)); | 1671 | lua_replace(L, lua_upvalueindex(2)); |