ina219_app_wifi_g2/src/ra/raConnection.cpp
/**
 * Z hesla sestavi sestavi sifrovaci klic pro login blok.
 * Zasifruje s nim verejny klic
 * Vygeneruje cely payload blok pro login a zapise ho na vystupni adresu.
 */
Z hesla sestavi sestavi sifrovaci klic pro login blok.
Zasifruje s nim verejny klic
Vygeneruje cely payload blok pro login a zapise ho na vystupni adresu.
Z hesla sestavi sestavi sifrovaci klic pro login blok . Zasifruje s nim verejny klic Vygeneruje cely payload blok pro login a zapise ho na vystupni adresu .
void raConnection::createLoginToken( BYTE *target, BYTE * ecdh_public )
{
    BYTE aes_iv[AES_BLOCKLEN];
    this->sha256->init();
    const char * pass = this->cfg->getString( "$ra_pass", "???" );
    this->sha256->update((const BYTE *)pass, strlen((const char *)pass));
    this->sha256->final(this->sessionKey);
    random_block( aes_iv, AES_BLOCKLEN );
    btohexa( aes_iv, AES_BLOCKLEN, (char *)target, 130 );
#ifdef DETAILED_RA_LOG
    this->logger->log( "  password: '%s'", this->cfg->getString( "$ra_pass", "???" ) );
    btohexa( this->sessionKey, SHA256_BLOCK_SIZE, log_buffer, LOG_BUFFER_LENGTH );
    this->logger->log( "  password hash: %s", log_buffer );
    this->logger->log( "  IV: %s", target );
#endif        
#define LOGIN_PAYLOAD_LEN 64
    BYTE msg[LOGIN_PAYLOAD_LEN+1] ;
    memcpy( msg, ecdh_public, LOGIN_PAYLOAD_LEN );
    struct AES_ctx ctx;
    AES_init_ctx_iv(&ctx, (unsigned char const*)this->sessionKey, (unsigned char const*)aes_iv);
    AES_CBC_encrypt_buffer(&ctx, (unsigned char *)msg, LOGIN_PAYLOAD_LEN );
    char * output_ptr = (char *)target + AES_BLOCKLEN+AES_BLOCKLEN;
    output_ptr[0] = ':';
    output_ptr++;
    btohexa( msg, LOGIN_PAYLOAD_LEN, output_ptr, LOGIN_PAYLOAD_LEN+LOGIN_PAYLOAD_LEN+1 );  
}
void raConnection :: createLoginToken ( BYTE * target , BYTE * ecdh_public ) { BYTE aes_iv [ AES_BLOCKLEN ] ; this -> sha256 -> init ( ) ; const char * pass = this -> cfg -> getString ( " " , " " ) ; this -> sha256 -> update ( ( const BYTE * ) pass , strlen ( ( const char * ) pass ) ) ; this -> sha256 -> final ( this -> sessionKey ) ; random_block ( aes_iv , AES_BLOCKLEN ) ; btohexa ( aes_iv , AES_BLOCKLEN , ( char * ) target , 130 ) ; #ifdef DETAILED_RA_LOG this -> logger -> log ( " " , this -> cfg -> getString ( " " , " " ) ) ; btohexa ( this -> sessionKey , SHA256_BLOCK_SIZE , log_buffer , LOG_BUFFER_LENGTH ) ; this -> logger -> log ( " " , log_buffer ) ; this -> logger -> log ( " " , target ) ; #endif #define LOGIN_PAYLOAD_LEN  64 BYTE msg [ LOGIN_PAYLOAD_LEN + 1 ] ; memcpy ( msg , ecdh_public , LOGIN_PAYLOAD_LEN ) ; struct AES_ctx ctx ; AES_init_ctx_iv ( & ctx , ( unsigned char const * ) this -> sessionKey , ( unsigned char const * ) aes_iv ) ; AES_CBC_encrypt_buffer ( & ctx , ( unsigned char * ) msg , LOGIN_PAYLOAD_LEN ) ; char * output_ptr = ( char * ) target + AES_BLOCKLEN + AES_BLOCKLEN ; output_ptr [ 0 ] = ' ' ; output_ptr ++ ; btohexa ( msg , LOGIN_PAYLOAD_LEN , output_ptr , LOGIN_PAYLOAD_LEN + LOGIN_PAYLOAD_LEN + 1 ) ; }
Z hesla sestavi sestavi sifrovaci klic pro login blok.
Z hesla sestavi sestavi sifrovaci klic pro login blok .
// tohle neni debug, ale uz si konstruuji zpravu! // preskocime za IV