@@ -1521,3 +1521,228 @@ WOLFSSH_CHANNEL* channel );
1521
1521
```
1522
1522
1523
1523
1524
+ ## Key Load Functions
1525
+
1526
+
1527
+ ### wolfSSH_ReadKey_buffer()
1528
+
1529
+ ** Synopsis**
1530
+
1531
+ ```
1532
+ #include <wolfssh/ssh.h>
1533
+
1534
+ int wolfSSH_ReadKey_buffer(const byte* in, word32 inSz,
1535
+ int format, byte** out, word32* outSz,
1536
+ const byte** outType, word32* outTypeSz,
1537
+ void* heap);
1538
+ ```
1539
+
1540
+ ** Description**
1541
+
1542
+ Reads a key file from the buffer _ in_ of size _ inSz_ and tries to decode it
1543
+ as a _ format_ type key. The _ format_ can be ** WOLFSSH_FORMAT_ASN1** ,
1544
+ ** WOLFSSH_FORMAT_PEM** , ** WOLFSSH_FORMAT_SSH** , or ** WOLFSSH_FORMAT_OPENSSH** .
1545
+ The key ready for use by ` wolfSSH_UsePrivateKey_buffer() ` is stored in the
1546
+ buffer pointed to by _ out_ , of size _ outSz_ . If _ out_ is NULL, _ heap_ is used
1547
+ to allocate a buffer for the key. The type string of the key is stored in
1548
+ _ outType_ , with its string length in _ outTypeSz_ .
1549
+
1550
+ ** Return Values**
1551
+
1552
+ * ** WS_SUCCESS** - read key is successful
1553
+ * ** WS_BAD_ARGUMENT** - parameter has a bad value
1554
+ * ** WS_MEMORY_E** - failure allocating memory
1555
+ * ** WS_BUFFER_E** - buffer not large enough for indicated size
1556
+ * ** WS_PARSE_E** - problem parsing the key file
1557
+ * ** WS_UNIMPLEMENTED_E** - key type not supported
1558
+ * ** WS_RSA_E** - something wrong with RSA (PKCS1) key
1559
+ * ** WS_ECC_E** - something wrong with ECC (X9.63) key
1560
+ * ** WS_KEY_AUTH_MAGIC_E** - OpenSSH key auth magic value bad
1561
+ * ** WS_KEY_FORMAT_E** - OpenSSH key format incorrect
1562
+ * ** WS_KEY_CHECK_VAL_E** - OpenSSH key check value corrupt
1563
+
1564
+
1565
+ ### wolfSSH_ReadKey_file()
1566
+
1567
+ ** Synopsis**
1568
+
1569
+ ```
1570
+ #include <wolfssh/ssh.h>
1571
+
1572
+ int wolfSSH_ReadKey_file(const char* name,
1573
+ byte** out, word32* outSz,
1574
+ const byte** outType, word32* outTypeSz,
1575
+ byte* isPrivate, void* heap);
1576
+ ```
1577
+
1578
+ ** Description**
1579
+
1580
+ Reads the key from the file _ name_ . The format is guessed based on data in
1581
+ the file. The key buffer _ out_ , the key type _ outType_ , and their sizes
1582
+ are passed to ` wolfSSH_ReadKey_buffer() ` . The flag _ isPrivate_ is set
1583
+ as appropriate. Any memory allocations use the specified _ heap_ .
1584
+
1585
+ ** Return Values**
1586
+
1587
+ * ** WS_SUCCESS** - read key is successful
1588
+ * ** WS_BAD_ARGUMENT** - parameter has a bad value
1589
+ * ** WS_BAD_FILE_E** - problem reading the file
1590
+ * ** WS_MEMORY_E** - failure allocating memory
1591
+ * ** WS_BUFFER_E** - buffer not large enough for indicated size
1592
+ * ** WS_PARSE_E** - problem parsing the key file
1593
+ * ** WS_UNIMPLEMENTED_E** - key type not supported
1594
+ * ** WS_RSA_E** - something wrong with RSA (PKCS1) key
1595
+ * ** WS_ECC_E** - something wrong with ECC (X9.63) key
1596
+ * ** WS_KEY_AUTH_MAGIC_E** - OpenSSH key auth magic value bad
1597
+ * ** WS_KEY_FORMAT_E** - OpenSSH key format incorrect
1598
+ * ** WS_KEY_CHECK_VAL_E** - OpenSSH key check value corrupt
1599
+
1600
+
1601
+ ## Key Exchange Algorithm Configuration
1602
+
1603
+ wolfSSH sets up a set of algorithm lists used during the Key Exchange (KEX)
1604
+ based on the availability of algorithms in the wolfCrypt library used.
1605
+
1606
+ Provided are some accessor functions to see which algorithms are available
1607
+ to use and to see the algorithm lists used in the KEX. The accessor functions
1608
+ come in sets of four: set or get from CTX object, and set or get from SSH
1609
+ object. All SSH objects made with a CTX inherit the CTX's algorithm lists,
1610
+ and they may be provided their own.
1611
+
1612
+ By default, any algorithms using SHA-1 are disabled but may be re-enabled
1613
+ using one of the following functions. If SHA-1 is disabled in wolfCrypt, then
1614
+ SHA-1 cannot be used.
1615
+
1616
+
1617
+ ### wolfSSH Set Algo Lists
1618
+
1619
+ ** Synopsis**
1620
+
1621
+ ```
1622
+ #include <wolfssh/ssh.h>
1623
+
1624
+ int wolfSSH_CTX_SetAlgoListKex(WOLFSSH_CTX* ctx, const char* list);
1625
+ int wolfSSH_CTX_SetAlgoListKey(WOLFSSH_CTX* ctx, const char* list);
1626
+ int wolfSSH_CTX_SetAlgoListCipher(WOLFSSH_CTX* ctx, const char* list);
1627
+ int wolfSSH_CTX_SetAlgoListMac(WOLFSSH_CTX* ctx, const char* list);
1628
+ int wolfSSH_CTX_SetAlgoListKeyAccepted(WOLFSSH_CTX* ctx, const char* list);
1629
+
1630
+ int wolfSSH_SetAlgoListKex(WOLFSSH* ssh, const char* list);
1631
+ int wolfSSH_SetAlgoListKey(WOLFSSH* ssh, const char* list);
1632
+ int wolfSSH_SetAlgoListCipher(WOLFSSH* ssh, const char* list);
1633
+ int wolfSSH_SetAlgoListMac(WOLFSSH* ssh, const char* list);
1634
+ int wolfSSH_SetAlgoListKeyAccepted(WOLFSSH* ssh, const char* list);
1635
+ ```
1636
+
1637
+ ** Description**
1638
+
1639
+ These functions act as setters for the various algorithm lists set in the
1640
+ wolfSSH _ ctx_ or _ ssh_ objects. The strings are sent to the peer during the
1641
+ KEX Initialization and are used to compare against when the peer sends its
1642
+ KEX Initialization message. The KeyAccepted list is used for user
1643
+ authentication.
1644
+
1645
+ The CTX versions of the functions set the algorithm list for the specified
1646
+ WOLFSSH_CTX object, _ ctx_ . They have default values set at compile time. The
1647
+ specified value is used instead. Note, the library does not copy this string,
1648
+ it is owned by the application and it is up to the application to free it
1649
+ when the CTX is deallocated by the application. When creating an SSH object
1650
+ using a CTX, the SSH object inherits the CTX's strings. The SSH object
1651
+ algorithm lists may be overridden.
1652
+
1653
+ ` Kex ` specifies the key exchange algorithm list. ` Key ` specifies the server
1654
+ public key algorithm list. ` Cipher ` specifies the bulk encryption algorithm
1655
+ list. ` Mac ` specifies the message authentication code algorithm list.
1656
+ ` KeyAccepted ` specifies the public key algorithms allowed for user
1657
+ authentication.
1658
+
1659
+ ** Return Values**
1660
+
1661
+ * ** WS_SUCCESS** - successful
1662
+ * ** WS_SSH_CTX_NULL_E** - provided CTX was null
1663
+ * ** WS_SSH_NULL_E** - provide SSH was null
1664
+
1665
+
1666
+ ### wolfSSH Get Algo List
1667
+
1668
+ ** Synopsis**
1669
+
1670
+ ```
1671
+ #include <wolfssh/ssh.h>
1672
+
1673
+ const char* wolfSSH_CTX_GetAlgoListKex(WOLFSSH_CTX* ctx);
1674
+ const char* wolfSSH_CTX_GetAlgoListKey(WOLFSSH_CTX* ctx);
1675
+ const char* wolfSSH_CTX_GetAlgoListCipher(WOLFSSH_CTX* ctx);
1676
+ const char* wolfSSH_CTX_GetAlgoListMac(WOLFSSH_CTX* ctx);
1677
+ const char* wolfSSH_CTX_GetAlgoListKeyAccepted(WOLFSSH_CTX* ctx);
1678
+
1679
+ const char* wolfSSH_GetAlgoListKex(WOLFSSH* ssh);
1680
+ const char* wolfSSH_GetAlgoListKey(WOLFSSH* ssh);
1681
+ const char* wolfSSH_GetAlgoListCipher(WOLFSSH* ssh);
1682
+ const char* wolfSSH_GetAlgoListMac(WOLFSSH* ssh);
1683
+ const char* wolfSSH_GetAlgoListKeyAccepted(WOLFSSH* ssh);
1684
+ ```
1685
+
1686
+ ** Description**
1687
+
1688
+ These functions act as getters for the various algorithm lists set in the
1689
+ wolfSSH _ ctx_ or _ ssh_ objects.
1690
+
1691
+ ` Kex ` specifies the key exchange algorithm list. ` Key ` specifies the server
1692
+ public key algorithm list. ` Cipher ` specifies the bulk encryption algorithm
1693
+ list. ` Mac ` specifies the message authentication code algorithm list.
1694
+ ` KeyAccepted ` specifies the public key algorithms allowed for user
1695
+ authentication.
1696
+
1697
+ ** Return Values**
1698
+
1699
+ These functions return a pointer to either the default value set at compile
1700
+ time or the value set at run time with the setter functions. If the _ ctx_
1701
+ or ` ssh ` parameters are NULL the functions return NULL.
1702
+
1703
+
1704
+ ### wolfSSH_CheckAlgoName
1705
+
1706
+ ** Synopsis**
1707
+
1708
+ ```
1709
+ #include <wolfssh/ssh.h>
1710
+
1711
+ int wolfSSH_CheckAlgoName(const char* name);
1712
+ ```
1713
+
1714
+ ** Description**
1715
+
1716
+ Given a single algorithm _ name_ checks to see if it is valid.
1717
+
1718
+ ** Return Values**
1719
+
1720
+ * ** WS_SUCCESS** - _ name_ is a valid algorithm name
1721
+ * ** WS_INVALID_ALGO_ID** - _ name_ is an invalid algorithm name
1722
+
1723
+
1724
+ ### wolfSSH Query Algorithms
1725
+
1726
+ ** Synopsis**
1727
+
1728
+ ```
1729
+ #include <wolfssh/ssh.h>
1730
+
1731
+ const char* wolfSSH_QueryKex(word32* index);
1732
+ const char* wolfSSH_QueryKey(word32* index);
1733
+ const char* wolfSSH_QueryCipher(word32* index);
1734
+ const char* wolfSSH_QueryMac(word32* index);
1735
+ ```
1736
+
1737
+ ** Description**
1738
+
1739
+ Returns the name string for a valid algorithm of the particular type: Kex,
1740
+ Key, Cipher, or Mac. Note, Key types are also used for the user authentication
1741
+ accepted key types. The value passed as _ index_ must be initialized to 0,
1742
+ the passed in on each call to the function. At the end of the list, the
1743
+ _ index_ is invalid.
1744
+
1745
+ ** Return Values**
1746
+
1747
+ Returns a constant string with the name of an algorithm. Null indicates the
1748
+ end of the list.
0 commit comments