Update tutorial-tcp-psk.md
parent
f058b3f301
commit
207541712c
|
@ -251,80 +251,6 @@ Session resumption allows a client/server pair to re-use previously generated cr
|
|||
CyaSSL_Cleanup();
|
||||
|
||||
|
||||
## **Tutorial for adding Cyassl Security and PSK (Pre shared Keys) to a Simple Client.**
|
||||
|
||||
1. Include the CyaSSL compatibility header:
|
||||
```
|
||||
#include <cyassl/ssl.h>
|
||||
```
|
||||
|
||||
* Change all calls from read() or recv() to CyaSSL_read(), in the simple client
|
||||
```
|
||||
read(sockfd, recvline, MAXLINE)
|
||||
```
|
||||
becomes
|
||||
```
|
||||
CyaSSL_read(ssl, recvline, MAXLINE)
|
||||
```
|
||||
|
||||
3. Change all calls from write() or send() to CySSL_write(), in the simple client ``` write(socked, send line,strlen(send line)) ``` becomes ``` CyaSSL_write(ssl, send line, strlen(sendline))```
|
||||
|
||||
4. In the main method initialize CyaSSL and CYASSL_CTX.
|
||||
|
||||
CyaSSL_Init();
|
||||
|
||||
if ((ctx = CyaSSL_CTX_new(CyaTLSv1_2_client_method())) == NULL)
|
||||
fprintf(stderr, "SSL_CTX_new error.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
5. Create the CyaSSL object after each TCP connect and associate the file descriptor with the session:
|
||||
|
||||
if ( (ssl = CyaSSL_new(ctx)) == NULL) {
|
||||
fprintf(stderr, "CyaSSL_new error.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = CyaSSL_set_fd(ssl, sockfd);
|
||||
if (ret != SSL_SUCCESS){
|
||||
return 1;
|
||||
}
|
||||
|
||||
6. Cleanup. After each CyaSSL object is done being used you can free it up by calling `CyaSSL_free(ssl);`
|
||||
7. When completely done using SSL/TLS, free the CYASSL_CTX object by `CyaSSL_CTX_free(CTX);`
|
||||
`CyaSSL_Cleanup();`
|
||||
|
||||
**Now we add Pre-Shared Keys (PSK) to the CyaSSL Simple Client **
|
||||
|
||||
1. When configuring CyaSSL
|
||||
`sudo ./configure --enable-psk`
|
||||
`sudo make`
|
||||
`sudo make install`
|
||||
|
||||
* In the main method add
|
||||
`CyaSSL_CTX_set_psk_client_callback(ctx, My_Psk_Client_cb);`
|
||||
|
||||
3. Add the function
|
||||
|
||||
static inline unsigned int My_Psk_Client_Cb(CYASSL* ssl, const char* hint,
|
||||
char* identity, unsigned int id_max_len, unsigned char* key,
|
||||
unsigned int key_max_len)
|
||||
{
|
||||
(void)ssl;
|
||||
(void)hint;
|
||||
(void)key_max_len;
|
||||
|
||||
strncpy(identity, "Client_identity", id_max_len);
|
||||
|
||||
key[0] = 26;
|
||||
key[1] = 43;
|
||||
key[2] = 60;
|
||||
key[3] = 77;
|
||||
|
||||
return 4;
|
||||
}
|
||||
|
||||
|
||||
## **Tutorial for adding Cyassl Security and PSK (Pre shared Keys) to a Simple Server.**
|
||||
|
||||
1. Include the CyaSSL compatibility header:
|
||||
|
|
Loading…
Reference in New Issue