Fix some bugs in the TLSv1.3 PSK code
[openssl.git] / ssl / statem / extensions_srvr.c
index 4e65320df2c772929b0869b6b5673bc57725d7ee..3da9f556e9453a76361bce0340a7f724d44f7d69 100644 (file)
@@ -713,8 +713,15 @@ int tls_parse_ctos_psk(SSL *s, PACKET *pkt, unsigned int context, X509 *x,
         }
 
         if (s->psk_find_session_cb != NULL
-                && s->psk_find_session_cb(s, PACKET_data(&identity),
-                                          PACKET_remaining(&identity), &sess)) {
+                && !s->psk_find_session_cb(s, PACKET_data(&identity),
+                                           PACKET_remaining(&identity),
+                                           &sess)) {
+            *al = SSL_AD_INTERNAL_ERROR;
+            return 0;
+        }
+
+        if (sess != NULL) {
+            /* We found a PSK */
             SSL_SESSION *sesstmp = ssl_session_dup(sess, 0);
 
             if (sesstmp == NULL) {