picoquic/tls_api.c
int picoquic_server_encrypt_ticket_call_back(ptls_encrypt_ticket_t* encrypt_ticket_ctx,
    ptls_t* tls, int is_encrypt, ptls_buffer_t* dst, ptls_iovec_t src)
{
#ifdef _WINDOWS
    UNREFERENCED_PARAMETER(tls);
#endif

    /* Assume that the keys are in the quic context 
     * The tickets are composed of a 64 bit "sequence number" 
     * followed by the result of the clear text encryption.
     */
    int ret = 0;
    picoquic_quic_t** ppquic = (picoquic_quic_t**)(((char*)encrypt_ticket_ctx) + sizeof(ptls_encrypt_ticket_t));
    picoquic_quic_t* quic = *ppquic;

    if (is_encrypt != 0) {
        ptls_aead_context_t* aead_enc = (ptls_aead_context_t*)quic->aead_encrypt_ticket_ctx;
        /* Encoding*/
        if (aead_enc == NULL) {
            ret = -1;
        } else if ((ret = ptls_buffer_reserve(dst, 8 + src.len + aead_enc->algo->tag_size)) == 0) {
            /* Create and store the ticket sequence number */
            uint64_t seq_num = picoquic_public_random_64();
            picoformat_64(dst->base + dst->off, seq_num);
            dst->off += 8;
            /* Run AEAD encryption */
            dst->off += ptls_aead_encrypt(aead_enc, dst->base + dst->off,
                src.base, src.len, seq_num, NULL, 0);
        }
    } else {
        ptls_aead_context_t* aead_dec = (ptls_aead_context_t*)quic->aead_decrypt_ticket_ctx;
        /* Encoding*/
        if (aead_dec == NULL) {
            ret = -1;
        } else if (src.len < 8 + aead_dec->algo->tag_size) {
            ret = -1;
        } else if ((ret = ptls_buffer_reserve(dst, src.len)) == 0) {
            /* Decode the ticket sequence number */
            uint64_t seq_num = PICOPARSE_64(src.base);
            /* Decrypt */
            size_t decrypted = ptls_aead_decrypt(aead_dec, dst->base + dst->off,
                src.base + 8, src.len - 8, seq_num, NULL, 0);

            if (decrypted > src.len - 8) {
                /* decryption error */
                ret = -1;
                if (quic->F_log != NULL) {
                    picoquic_log_app_message(quic->cnx_in_progress, "%s",
                        "Session ticket could not be decrypted");
                }
            } else {
                dst->off += decrypted;
                if (quic->F_log != NULL) {
                    picoquic_log_app_message(quic->cnx_in_progress, "%s",
                        "Session ticket properly decrypted");
                }
            }
        }
    }

    return ret;
}
/*
 * The server will generate session tickets if some parameters are set in the server
 * TLS context, including:
 *  - the session ticket encryption callback, defined per the "encrypt_ticket" member of the context.
 *  - the session ticket lifetime, defined per the "ticket_life_time" member of the context.
 * The encrypt call back is called on the server side when a session resume ticket is ready.
 * The call is:
 * cb(tls->ctx->encrypt_ticket, tls, 1, sendbuf,
 *    ptls_iovec_init(session_id.base, session_id.off))
 * The call to decrypt is:
 * tls->ctx->encrypt_ticket->cb(tls->ctx->encrypt_ticket, tls, 0, &decbuf, identity->identity)
 * Should return 0 if the ticket is good, etc.
 */
The server will generate session tickets if some parameters are set in the server
TLS context, including:
- the session ticket encryption callback, defined per the "encrypt_ticket" member of the context.
- the session ticket lifetime, defined per the "ticket_life_time" member of the context.
The encrypt call back is called on the server side when a session resume ticket is ready.
The server will generate session tickets if some parameters are set in the server TLS context including : - the session ticket encryption callback defined per the " encrypt_ticket " member of the context . - the session ticket lifetime defined per the " ticket_life_time " member of the context . The encrypt call back is called on the server side when a session resume ticket is ready .
int picoquic_server_encrypt_ticket_call_back(ptls_encrypt_ticket_t* encrypt_ticket_ctx,
    ptls_t* tls, int is_encrypt, ptls_buffer_t* dst, ptls_iovec_t src)
{
#ifdef _WINDOWS
    UNREFERENCED_PARAMETER(tls);
#endif
    int ret = 0;
    picoquic_quic_t** ppquic = (picoquic_quic_t**)(((char*)encrypt_ticket_ctx) + sizeof(ptls_encrypt_ticket_t));
    picoquic_quic_t* quic = *ppquic;
    if (is_encrypt != 0) {
        ptls_aead_context_t* aead_enc = (ptls_aead_context_t*)quic->aead_encrypt_ticket_ctx;
        if (aead_enc == NULL) {
            ret = -1;
        } else if ((ret = ptls_buffer_reserve(dst, 8 + src.len + aead_enc->algo->tag_size)) == 0) {
            uint64_t seq_num = picoquic_public_random_64();
            picoformat_64(dst->base + dst->off, seq_num);
            dst->off += 8;
            dst->off += ptls_aead_encrypt(aead_enc, dst->base + dst->off,
                src.base, src.len, seq_num, NULL, 0);
        }
    } else {
        ptls_aead_context_t* aead_dec = (ptls_aead_context_t*)quic->aead_decrypt_ticket_ctx;
        if (aead_dec == NULL) {
            ret = -1;
        } else if (src.len < 8 + aead_dec->algo->tag_size) {
            ret = -1;
        } else if ((ret = ptls_buffer_reserve(dst, src.len)) == 0) {
            uint64_t seq_num = PICOPARSE_64(src.base);
            size_t decrypted = ptls_aead_decrypt(aead_dec, dst->base + dst->off,
                src.base + 8, src.len - 8, seq_num, NULL, 0);
            if (decrypted > src.len - 8) {
                ret = -1;
                if (quic->F_log != NULL) {
                    picoquic_log_app_message(quic->cnx_in_progress, "%s",
                        "Session ticket could not be decrypted");
                }
            } else {
                dst->off += decrypted;
                if (quic->F_log != NULL) {
                    picoquic_log_app_message(quic->cnx_in_progress, "%s",
                        "Session ticket properly decrypted");
                }
            }
        }
    }
    return ret;
}
int picoquic_server_encrypt_ticket_call_back ( ptls_encrypt_ticket_t * encrypt_ticket_ctx , ptls_t * tls , int is_encrypt , ptls_buffer_t * dst , ptls_iovec_t src ) { #ifdef _WINDOWS UNREFERENCED_PARAMETER ( tls ) ; #endif int ret = 0 ; picoquic_quic_t * * ppquic = ( picoquic_quic_t * * ) ( ( ( char * ) encrypt_ticket_ctx ) + sizeof ( ptls_encrypt_ticket_t ) ) ; picoquic_quic_t * quic = * ppquic ; if ( is_encrypt != 0 ) { ptls_aead_context_t * aead_enc = ( ptls_aead_context_t * ) quic -> aead_encrypt_ticket_ctx ; if ( aead_enc == NULL ) { ret = -1 ; } else if ( ( ret = ptls_buffer_reserve ( dst , 8 + src . len + aead_enc -> algo -> tag_size ) ) == 0 ) { uint64_t seq_num = picoquic_public_random_64 ( ) ; picoformat_64 ( dst -> base + dst -> off , seq_num ) ; dst -> off += 8 ; dst -> off += ptls_aead_encrypt ( aead_enc , dst -> base + dst -> off , src . base , src . len , seq_num , NULL , 0 ) ; } } else { ptls_aead_context_t * aead_dec = ( ptls_aead_context_t * ) quic -> aead_decrypt_ticket_ctx ; if ( aead_dec == NULL ) { ret = -1 ; } else if ( src . len < 8 + aead_dec -> algo -> tag_size ) { ret = -1 ; } else if ( ( ret = ptls_buffer_reserve ( dst , src . len ) ) == 0 ) { uint64_t seq_num = PICOPARSE_64 ( src . base ) ; size_t decrypted = ptls_aead_decrypt ( aead_dec , dst -> base + dst -> off , src . base + 8 , src . len - 8 , seq_num , NULL , 0 ) ; if ( decrypted > src . len - 8 ) { ret = -1 ; if ( quic -> F_log != NULL ) { picoquic_log_app_message ( quic -> cnx_in_progress , " " , " " ) ; } } else { dst -> off += decrypted ; if ( quic -> F_log != NULL ) { picoquic_log_app_message ( quic -> cnx_in_progress , " " , " " ) ; } } } } return ret ; }
The server will generate session tickets if some parameters are set in the server
 TLS context, including:
  - the session ticket encryption callback, defined per the "encrypt_ticket" member of the context.
The server will generate session tickets if some parameters are set in the server TLS context including : - the session ticket encryption callback defined per the " encrypt_ticket " member of the context .
/* Assume that the keys are in the quic context 
     * The tickets are composed of a 64 bit "sequence number" 
     * followed by the result of the clear text encryption.
     */ /* Encoding*/ /* Create and store the ticket sequence number */ /* Run AEAD encryption */ /* Encoding*/ /* Decode the ticket sequence number */ /* Decrypt */ /* decryption error */