michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* This program demonstrates the use of SSL_GetCipherSuiteInfo to avoid michael@0: * all compiled-in knowledge of SSL cipher suites. michael@0: * michael@0: * Try: ./listsuites | grep -v : | sort -b +4rn -5 +1 -2 +2 -3 +3 -4 +5r -6 michael@0: */ michael@0: michael@0: #include michael@0: #include michael@0: #include "secport.h" michael@0: #include "ssl.h" michael@0: michael@0: int main(int argc, char **argv) michael@0: { michael@0: const PRUint16 *cipherSuites = SSL_ImplementedCiphers; michael@0: int i; michael@0: int errCount = 0; michael@0: michael@0: fputs("This version of libSSL supports these cipher suites:\n\n", stdout); michael@0: michael@0: /* disable all the SSL3 cipher suites */ michael@0: for (i = 0; i < SSL_NumImplementedCiphers; i++) { michael@0: PRUint16 suite = cipherSuites[i]; michael@0: SECStatus rv; michael@0: PRBool enabled; michael@0: PRErrorCode err; michael@0: SSLCipherSuiteInfo info; michael@0: michael@0: rv = SSL_CipherPrefGetDefault(suite, &enabled); michael@0: if (rv != SECSuccess) { michael@0: err = PR_GetError(); michael@0: ++errCount; michael@0: fprintf(stderr, michael@0: "SSL_CipherPrefGetDefault didn't like value 0x%04x (i = %d): %s\n", michael@0: suite, i, PORT_ErrorToString(err)); michael@0: continue; michael@0: } michael@0: rv = SSL_GetCipherSuiteInfo(suite, &info, (int)(sizeof info)); michael@0: if (rv != SECSuccess) { michael@0: err = PR_GetError(); michael@0: ++errCount; michael@0: fprintf(stderr, michael@0: "SSL_GetCipherSuiteInfo didn't like value 0x%04x (i = %d): %s\n", michael@0: suite, i, PORT_ErrorToString(err)); michael@0: continue; michael@0: } michael@0: fprintf(stdout, michael@0: "%s:\n" /* up to 37 spaces */ michael@0: " 0x%04hx %-5s %-5s %-8s %3hd %-6s %-8s %-4s %-8s %-11s\n", michael@0: info.cipherSuiteName, info.cipherSuite, michael@0: info.keaTypeName, info.authAlgorithmName, info.symCipherName, michael@0: info.effectiveKeyBits, info.macAlgorithmName, michael@0: enabled ? "Enabled" : "Disabled", michael@0: info.isFIPS ? "FIPS" : michael@0: (SSL_IS_SSL2_CIPHER(info.cipherSuite) ? "SSL2" : ""), michael@0: info.isExportable ? "Export" : "Domestic", michael@0: info.nonStandard ? "nonStandard" : ""); michael@0: } michael@0: return errCount; michael@0: }