if (scs.tag_size == 0) { if (gcm_on) {
scs.tag_size = 16;
} else {
scs.tag_size = 10;
}
}
if (gcm_on && scs.tag_size != 8 && scs.tag_size != 16) {
fprintf(stderr, "error: GCM tag size must be 8 or 16 (%d)\n",
scs.tag_size); exit(1);
}
if (!gcm_on && scs.tag_size != 4 && scs.tag_size != 10) {
fprintf(stderr, "error: non GCM tag size must be 4 or 10 (%d)\n",
scs.tag_size); exit(1);
}
if (do_list_mods) {
status = srtp_list_debug_modules(); if (status) {
fprintf(stderr, "error: list of debug modules failed\n"); exit(1);
} return0;
}
if ((sec_servs && !input_key) || (!sec_servs && input_key)) { /* *akeymustbeprovidedifandonlyifsecurityserviceshave *beenrequested
*/ if (input_key == NULL) {
fprintf(stderr, "key not provided\n");
} if (!sec_servs) {
fprintf(stderr, "no secservs\n");
}
fprintf(stderr, "provided\n");
usage(argv[0]);
}
/* report security services selected on the command line */
fprintf(stderr, "security services: "); if (sec_servs & sec_serv_conf)
fprintf(stderr, "confidentiality "); if (sec_servs & sec_serv_auth)
fprintf(stderr, "message authentication"); if (sec_servs == sec_serv_none)
fprintf(stderr, "none");
fprintf(stderr, "\n");
/* set up the srtp policy and master key */ if (sec_servs) { /* *createpolicystructure,usingthedefaultmechanismsbut *withonlythesecurityservicesrequestedonthecommandline, *usingtherightSSRCvalue
*/ switch (sec_servs) { case sec_serv_conf_and_auth: if (gcm_on) { #ifdef OPENSSL switch (scs.key_size) { case128: if (scs.tag_size == 16) {
srtp_crypto_policy_set_aes_gcm_128_16_auth(&policy.rtp);
srtp_crypto_policy_set_aes_gcm_128_16_auth(
&policy.rtcp);
} else {
srtp_crypto_policy_set_aes_gcm_128_8_auth(&policy.rtp);
srtp_crypto_policy_set_aes_gcm_128_8_auth(&policy.rtcp);
} break; case256: if (scs.tag_size == 16) {
srtp_crypto_policy_set_aes_gcm_256_16_auth(&policy.rtp);
srtp_crypto_policy_set_aes_gcm_256_16_auth(
&policy.rtcp);
} else {
srtp_crypto_policy_set_aes_gcm_256_8_auth(&policy.rtp);
srtp_crypto_policy_set_aes_gcm_256_8_auth(&policy.rtcp);
} break;
} #else
fprintf(stderr, "error: GCM mode only supported when using the " "OpenSSL crypto engine.\n"); return0; #endif
} else { switch (scs.key_size) { case128: if (scs.tag_size == 4) {
srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(
&policy.rtp);
srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(
&policy.rtcp);
} else {
srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(
&policy.rtp);
srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(
&policy.rtcp);
} break; case192: #ifdef OPENSSL if (scs.tag_size == 4) {
srtp_crypto_policy_set_aes_cm_192_hmac_sha1_32(
&policy.rtp);
srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80(
&policy.rtcp);
} else {
srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80(
&policy.rtp);
srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80(
&policy.rtcp);
} #else
fprintf(stderr, "error: AES 192 mode only supported when using the " "OpenSSL crypto engine.\n"); return0;
#endif break; case256: if (scs.tag_size == 4) {
srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32(
&policy.rtp);
srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(
&policy.rtcp);
} else {
srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(
&policy.rtp);
srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(
&policy.rtcp);
} break;
}
} break; case sec_serv_conf: if (gcm_on) {
fprintf(
stderr, "error: GCM mode must always be used with auth enabled\n"); return -1;
} else { switch (scs.key_size) { case128:
srtp_crypto_policy_set_aes_cm_128_null_auth(&policy.rtp);
srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(
&policy.rtcp); break; case192: #ifdef OPENSSL
srtp_crypto_policy_set_aes_cm_192_null_auth(&policy.rtp);
srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80(
&policy.rtcp); #else
fprintf(stderr, "error: AES 192 mode only supported when using the " "OpenSSL crypto engine.\n"); return0;
#endif break; case256:
srtp_crypto_policy_set_aes_cm_256_null_auth(&policy.rtp);
srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(
&policy.rtcp); break;
}
} break; case sec_serv_auth: if (gcm_on) { #ifdef OPENSSL switch (scs.key_size) { case128:
srtp_crypto_policy_set_aes_gcm_128_8_only_auth(&policy.rtp);
srtp_crypto_policy_set_aes_gcm_128_8_only_auth(
&policy.rtcp); break; case256:
srtp_crypto_policy_set_aes_gcm_256_8_only_auth(&policy.rtp);
srtp_crypto_policy_set_aes_gcm_256_8_only_auth(
&policy.rtcp); break;
} #else
printf("error: GCM mode only supported when using the OpenSSL " "crypto engine.\n"); return0; #endif
} else {
srtp_crypto_policy_set_null_cipher_hmac_sha1_80(&policy.rtp);
srtp_crypto_policy_set_rtcp_default(&policy.rtcp);
} break; default:
fprintf(stderr, "error: unknown security service requested\n"); return -1;
}
policy.key = (uint8_t *)key;
policy.next = NULL;
policy.window_size = 128;
policy.allow_repeat_tx = 0;
policy.rtp.sec_serv = sec_servs;
policy.rtcp.sec_serv =
sec_servs; // sec_serv_none; /* we don't do RTCP anyway */
fprintf(stderr, "setting tag len %d\n", scs.tag_size);
policy.rtp.auth_tag_len = scs.tag_size;
if (gcm_on && scs.tag_size != 8) {
fprintf(stderr, "set tag len %d\n", scs.tag_size);
policy.rtp.auth_tag_len = scs.tag_size;
}
/* *readkeyfromhexadecimalorbase64oncommandlineintoanoctet *string
*/ if (b64_input) { int pad;
expected_len = policy.rtp.cipher_key_len * 4 / 3;
len = base64_string_to_octet_string(key, &pad, input_key,
strlen(input_key));
} else {
expected_len = policy.rtp.cipher_key_len * 2;
len = hex_string_to_octet_string(key, input_key, expected_len);
} /* check that hex string is the right length */ if (len < expected_len) {
fprintf(stderr, "error: too few digits in key/salt " "(should be %d digits, found %d)\n",
expected_len, len); exit(1);
} if (strlen(input_key) > (size_t)policy.rtp.cipher_key_len * 2) {
fprintf(stderr, "error: too many digits in key/salt " "(should be %d hexadecimal digits, found %u)\n",
policy.rtp.cipher_key_len * 2, (unsigned)strlen(input_key)); exit(1);
}
int key_octets = (scs.key_size / 8); int salt_octets = policy.rtp.cipher_key_len - key_octets;
fprintf(stderr, "set master key/salt to %s/",
octet_string_hex_string(key, key_octets));
fprintf(stderr, "%s\n",
octet_string_hex_string(key + key_octets, salt_octets));
} else {
fprintf(stderr, "error: neither encryption or authentication were selected\n"); exit(1);
}
status = srtp_shutdown(); if (status) {
fprintf(stderr, "error: srtp shutdown failed with error code %d\n",
status); exit(1);
}
return0;
}
void usage(char *string)
{
fprintf(
stderr, "usage: %s [-d <debug>]* [[-k][-b] <key>] [-a][-t][-e] [-c " "<srtp-crypto-suite>] [-m <mode>] [-s <ssrc> [-r <roc>]]\n" "or %s -l\n" "where -a use message authentication\n" " -e <key size> use encryption (use 128 or 256 for key size)\n" " -g Use AES-GCM mode (must be used with -e)\n" " -t <tag size> Tag size to use (in GCM mode use 8 or 16)\n" " -k <key> sets the srtp master key given in hexadecimal\n" " -b <key> sets the srtp master key given in base64\n" " -l list debug modules\n" " -f \"<pcap filter>\" to filter only the desired SRTP packets\n" " -d <debug> turn on debugging for module <debug>\n" " -c \"<srtp-crypto-suite>\" to set both key and tag size based\n" " on RFC4568-style crypto suite specification\n" " -m <mode> set the mode to be one of [rtp]|rtcp|rtcp-mux\n" " -p <pcap file> path to pcap file (defaults to stdin)\n" " -o byte offset of RTP packet in capture (defaults to 42)\n" " -s <ssrc> restrict decrypting to the given SSRC (in host byte " "order)\n" " -r <roc> initial rollover counter, requires -s <ssrc> " "(defaults to 0)\n",
string, string); exit(1);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.