Str ssl_get_certificate(SSL * ssl, char *hostname) { BIO *bp; X509 *x; X509_NAME *xn; char *p; int len; Str s; char buf[2048]; Str amsg = NULL; Str emsg; char *ans; if (ssl == NULL) return NULL; x = SSL_get_peer_certificate(ssl); if (x == NULL) { if (accept_this_site && strcasecmp(accept_this_site->ptr, hostname) == 0) ans = "y"; else { /* FIXME: gettextize? */ emsg = Strnew_charp("No SSL peer certificate: accept? (y/n)"); ans = inputAnswer(emsg->ptr); } if (ans && TOLOWER(*ans) == 'y') /* FIXME: gettextize? */ amsg = Strnew_charp ("Accept SSL session without any peer certificate"); else { /* FIXME: gettextize? */ char *e = "This SSL session was rejected " "to prevent security violation: no peer certificate"; disp_err_message(e, FALSE); free_ssl_ctx(); return NULL; } if (amsg) disp_err_message(amsg->ptr, FALSE); ssl_accept_this_site(hostname); /* FIXME: gettextize? */ s = amsg ? amsg : Strnew_charp("valid certificate"); return s; } #ifdef USE_SSL_VERIFY /* check the cert chain. * The chain length is automatically checked by OpenSSL when we * set the verify depth in the ctx. */ if (ssl_verify_server) { long verr; if ((verr = SSL_get_verify_result(ssl)) != X509_V_OK) { const char *em = X509_verify_cert_error_string(verr); if (accept_this_site && strcasecmp(accept_this_site->ptr, hostname) == 0) ans = "y"; else { /* FIXME: gettextize? */ emsg = Sprintf("%s: accept? (y/n)", em); ans = inputAnswer(emsg->ptr); } if (ans && TOLOWER(*ans) == 'y') { /* FIXME: gettextize? */ amsg = Sprintf("Accept unsecure SSL session: " "unverified: %s", em); } else { /* FIXME: gettextize? */ char *e = Sprintf("This SSL session was rejected: %s", em)->ptr; disp_err_message(e, FALSE); free_ssl_ctx(); return NULL; } } } #endif emsg = ssl_check_cert_ident(x, hostname); if (emsg != NULL) { if (accept_this_site && strcasecmp(accept_this_site->ptr, hostname) == 0) ans = "y"; else { Str ep = Strdup(emsg); if (ep->length > COLS - 16) Strshrink(ep, ep->length - (COLS - 16)); Strcat_charp(ep, ": accept? (y/n)"); ans = inputAnswer(ep->ptr); } if (ans && TOLOWER(*ans) == 'y') { /* FIXME: gettextize? */ amsg = Strnew_charp("Accept unsecure SSL session:"); Strcat(amsg, emsg); } else { /* FIXME: gettextize? */ char *e = "This SSL session was rejected " "to prevent security violation"; disp_err_message(e, FALSE); free_ssl_ctx(); return NULL; } } if (amsg) disp_err_message(amsg->ptr, FALSE); ssl_accept_this_site(hostname); /* FIXME: gettextize? */ s = amsg ? amsg : Strnew_charp("valid certificate"); Strcat_charp(s, "\n"); xn = X509_get_subject_name(x); if (X509_NAME_get_text_by_NID(xn, NID_commonName, buf, sizeof(buf)) == -1) Strcat_charp(s, " subject=<unknown>"); else Strcat_m_charp(s, " subject=", buf, NULL); xn = X509_get_issuer_name(x); if (X509_NAME_get_text_by_NID(xn, NID_commonName, buf, sizeof(buf)) == -1) Strcat_charp(s, ": issuer=<unknown>"); else Strcat_m_charp(s, ": issuer=", buf, NULL); Strcat_charp(s, "\n\n"); bp = BIO_new(BIO_s_mem()); X509_print(bp, x); len = (int)BIO_ctrl(bp, BIO_CTRL_INFO, 0, (char *)&p); Strcat_charp_n(s, p, len); BIO_free_all(bp); X509_free(x); return s; }
void Vectored_Interrupt(int button){ char cString[4], currDiffString[4]; //GLCD_Clear(White); /* Clear graphical LCD display */ GLCD_SetBackColor(Blue); GLCD_SetTextColor(White); switch(button){ case USER_BUTTON: //GLCD_DisplayString(0, 0, __FI, "< --User Button -- >"); switch(currentState) { case WELCOME_SCREEN: // If on the welcome screen, set up difficulty screen GLCD_Clear(White); if(currentDifficulty == 0){ currentDifficulty = 1; } updateNextDifficulty(nextDifficulty); DisplayInstructions(); DrawBarGraph(BAR_X,BAR_Y,currentDifficulty * 20,BAR_HEIGHT,BAR_VALUE); currentState = DIFFICULTY_SCREEN; break; case DIFFICULTY_SCREEN: // Transition to Question Screen updateScoreAndDifficulty(currentScore, currentDifficulty, nextDifficulty); currentDifficulty = nextDifficulty; // Set the difficulty currentState = QUESTION_SCREEN; questionScreen(); // Display the question screen break; case QUESTION_SCREEN: // Question Screen uses countdown timer - no inputs break; case ANSWER_SCREEN: //answerScreen(); currentState = MARKING_SCREEN; // Mark the users answer break; case MARKING_SCREEN: // Mark the users answer attempt markAnswer(); currentDifficulty = nextDifficulty; // Set the difficulty currentState = NEXT_QUESTION; break; case NEXT_QUESTION: // Move on to next question currentDifficulty = nextDifficulty; // Set the difficulty currentState = QUESTION_SCREEN; questionScreen(); // Display the question screen break; }; //GLCD_DisplayString(6, 0, __FI, GenerateRandomString(5)); //doTone = ~doTone; break; case JOYSTICK_SELECT: //GLCD_DisplayString(0, 0, __FI, "< --JSTK Select -->"); // Left available for future program improvements break; case JOYSTICK_UP: //GLCD_DisplayString(0, 0, __FI, "< --JSTK UP -- >"); inputAnswer(JOYSTICK_UP); break; case JOYSTICK_DOWN: //GLCD_DisplayString(0, 0, __FI, "< --JSTK DOWN -- >"); inputAnswer(JOYSTICK_DOWN); break; case JOYSTICK_RIGHT: //GLCD_DisplayString(0, 0, __FI, "< --JSTK RIGHT-- >"); inputAnswer(JOYSTICK_RIGHT); break; case JOYSTICK_LEFT: //GLCD_DisplayString(0, 0, __FI, "< --JSTK LEFT -- >"); inputAnswer(JOYSTICK_LEFT); break; case POTENTIOMETER_TURNED: //sprintf(cString, "%02d", c); switch(currentState) { case DIFFICULTY_SCREEN: nextDifficulty = (c / 3) + 1; nextDifficulty = nextDifficulty > 5 ? 5 : nextDifficulty; sprintf(currDiffString, "%1d", nextDifficulty); //updateScoreAndDifficulty(currentScore, currDifficulty, nextDifficulty); updateNextDifficulty(nextDifficulty); DrawBarGraph(BAR_X,BAR_Y,nextDifficulty * 20,BAR_HEIGHT,BAR_VALUE); //GLCD_SetBackColor(Red); break; case WELCOME_SCREEN: break; default: nextDifficulty = (c / 3) + 1; nextDifficulty = nextDifficulty > 5 ? 5 : nextDifficulty; sprintf(currDiffString, "%1d", nextDifficulty); updateScoreAndDifficulty(currentScore, currentDifficulty, nextDifficulty); break; } break; default: break; } }