GNUTLS 中的 SNI,什么时候问?

SNI in GNUTLS, when to ask?

因此,我正在尝试在我的 GNUTLS 服务器中实施 SNI。

我的代码:

if(sniCallback != NULL) {
    size_t ds = 256;
    char data[ds];
    unsigned int type = (unsigned int)GNUTLS_NAME_DNS;
    int snir = gnutls_server_name_get(sessiond, &data[0], &ds, &type, (unsigned int)0);
    data[ds - 1] = 0; // the last one must always be [=10=]
    if(snir >= 0) {
        jstring js = (*this)->NewStringUTF(this, data);
        jlong snicert = (*this)->CallLongMethod(this, sniCallback, (*this)->GetMethodID(this, (*this)->GetObjectClass(this, sniCallback), "getSNICert", "(Ljava/lang/String;)J"), js);
        if(snicert > 0L) {
            struct cert* oc = (struct cert*)snicert;
            gnutls_credentials_set(sessiond, GNUTLS_CRD_CERTIFICATE, oc->cert);
        }
    } else {
        printf("%i\n", snir);
    }
}

(不要介意 JNI)

我得到 -56 错误代码,即 GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE,文档将其转换为尚未发送 SNI。我怎么知道我什么时候有 SNI 信息? AKA 我什么时候得到 Client Hello?我直接从 Chrome 得到这个,所以我知道有 SNI。顺便说一下,这就是 NIO。

和我一样的人,答案是:

gnutls_handshake_set_post_client_hello_function