Commit 7342f1c4 authored by David Fuhrmann's avatar David Fuhrmann

securetransport: Coding style unification

parent dc0ca561
...@@ -109,7 +109,7 @@ static int st_Error (vlc_tls_t *obj, int val) ...@@ -109,7 +109,7 @@ static int st_Error (vlc_tls_t *obj, int val)
errno = ECONNRESET; errno = ECONNRESET;
break; break;
default: default:
msg_Err (obj, "Found error %d", val); msg_Err(obj, "Found error %d", val);
errno = ECONNRESET; errno = ECONNRESET;
} }
return -1; return -1;
...@@ -133,14 +133,14 @@ static OSStatus st_SocketReadFunc (SSLConnectionRef connection, ...@@ -133,14 +133,14 @@ static OSStatus st_SocketReadFunc (SSLConnectionRef connection,
OSStatus retValue = noErr; OSStatus retValue = noErr;
ssize_t val; ssize_t val;
for(;;) { for (;;) {
val = read(sys->i_fd, currData, bytesToGo); val = read(sys->i_fd, currData, bytesToGo);
if (val <= 0) { if (val <= 0) {
if(val == 0) { if (val == 0) {
msg_Dbg(session, "found eof"); msg_Dbg(session, "found eof");
retValue = errSSLClosedGraceful; retValue = errSSLClosedGraceful;
} else { /* do the switch */ } else { /* do the switch */
switch(errno) { switch (errno) {
case ENOENT: case ENOENT:
/* connection closed */ /* connection closed */
retValue = errSSLClosedGraceful; retValue = errSSLClosedGraceful;
...@@ -165,7 +165,7 @@ static OSStatus st_SocketReadFunc (SSLConnectionRef connection, ...@@ -165,7 +165,7 @@ static OSStatus st_SocketReadFunc (SSLConnectionRef connection,
currData += val; currData += val;
} }
if(bytesToGo == 0) { if (bytesToGo == 0) {
/* filled buffer with incoming data, done */ /* filled buffer with incoming data, done */
break; break;
} }
...@@ -196,7 +196,7 @@ static OSStatus st_SocketWriteFunc (SSLConnectionRef connection, ...@@ -196,7 +196,7 @@ static OSStatus st_SocketWriteFunc (SSLConnectionRef connection,
val = write(sys->i_fd, (char *)data + bytesSent, dataLen - bytesSent); val = write(sys->i_fd, (char *)data + bytesSent, dataLen - bytesSent);
} while (val >= 0 && (bytesSent += val) < dataLen); } while (val >= 0 && (bytesSent += val) < dataLen);
if(val < 0) { if (val < 0) {
switch(errno) { switch(errno) {
case EAGAIN: case EAGAIN:
retValue = errSSLWouldBlock; retValue = errSSLWouldBlock;
...@@ -225,7 +225,7 @@ static int st_validateServerCertificate (vlc_tls_t *session, const char *hostnam ...@@ -225,7 +225,7 @@ static int st_validateServerCertificate (vlc_tls_t *session, const char *hostnam
SecCertificateRef leaf_cert = NULL; SecCertificateRef leaf_cert = NULL;
SecTrustRef trust = NULL; SecTrustRef trust = NULL;
OSStatus ret = SSLCopyPeerTrust (sys->p_context, &trust); OSStatus ret = SSLCopyPeerTrust(sys->p_context, &trust);
if (ret != noErr || trust == NULL) { if (ret != noErr || trust == NULL) {
msg_Err(session, "error getting certifictate chain"); msg_Err(session, "error getting certifictate chain");
return -1; return -1;
...@@ -237,7 +237,7 @@ static int st_validateServerCertificate (vlc_tls_t *session, const char *hostnam ...@@ -237,7 +237,7 @@ static int st_validateServerCertificate (vlc_tls_t *session, const char *hostnam
/* enable default root / anchor certificates */ /* enable default root / anchor certificates */
ret = SecTrustSetAnchorCertificates (trust, NULL); ret = SecTrustSetAnchorCertificates(trust, NULL);
if (ret != noErr) { if (ret != noErr) {
msg_Err(session, "error setting anchor certificates"); msg_Err(session, "error setting anchor certificates");
result = -1; result = -1;
...@@ -247,7 +247,7 @@ static int st_validateServerCertificate (vlc_tls_t *session, const char *hostnam ...@@ -247,7 +247,7 @@ static int st_validateServerCertificate (vlc_tls_t *session, const char *hostnam
SecTrustResultType trust_eval_result = 0; SecTrustResultType trust_eval_result = 0;
ret = SecTrustEvaluate(trust, &trust_eval_result); ret = SecTrustEvaluate(trust, &trust_eval_result);
if(ret != noErr) { if (ret != noErr) {
msg_Err(session, "error calling SecTrustEvaluate"); msg_Err(session, "error calling SecTrustEvaluate");
result = -1; result = -1;
goto out; goto out;
...@@ -270,44 +270,44 @@ static int st_validateServerCertificate (vlc_tls_t *session, const char *hostnam ...@@ -270,44 +270,44 @@ static int st_validateServerCertificate (vlc_tls_t *session, const char *hostnam
/* SSLCopyPeerCertificates is only available on OSX 10.5 or later */ /* SSLCopyPeerCertificates is only available on OSX 10.5 or later */
#if !TARGET_OS_IPHONE #if !TARGET_OS_IPHONE
CFArrayRef cert_chain = NULL; CFArrayRef cert_chain = NULL;
ret = SSLCopyPeerCertificates (sys->p_context, &cert_chain); ret = SSLCopyPeerCertificates(sys->p_context, &cert_chain);
if (ret != noErr || !cert_chain) { if (ret != noErr || !cert_chain) {
result = -1; result = -1;
goto out; goto out;
} }
if (CFArrayGetCount (cert_chain) == 0) { if (CFArrayGetCount(cert_chain) == 0) {
CFRelease (cert_chain); CFRelease(cert_chain);
result = -1; result = -1;
goto out; goto out;
} }
leaf_cert = (SecCertificateRef)CFArrayGetValueAtIndex (cert_chain, 0); leaf_cert = (SecCertificateRef)CFArrayGetValueAtIndex(cert_chain, 0);
CFRetain (leaf_cert); CFRetain(leaf_cert);
CFRelease (cert_chain); CFRelease(cert_chain);
#else #else
/* SecTrustGetCertificateAtIndex is only available on 10.7 or iOS */ /* SecTrustGetCertificateAtIndex is only available on 10.7 or iOS */
if (SecTrustGetCertificateCount (trust) == 0) { if (SecTrustGetCertificateCount(trust) == 0) {
result = -1; result = -1;
goto out; goto out;
} }
leaf_cert = SecTrustGetCertificateAtIndex (trust, 0); leaf_cert = SecTrustGetCertificateAtIndex(trust, 0);
CFRetain (leaf_cert); CFRetain(leaf_cert);
#endif #endif
/* check if leaf already accepted */ /* check if leaf already accepted */
CFIndex max = CFArrayGetCount (sys->p_cred->whitelist); CFIndex max = CFArrayGetCount(sys->p_cred->whitelist);
for (CFIndex i = 0; i < max; ++i) { for (CFIndex i = 0; i < max; ++i) {
CFDictionaryRef dict = CFArrayGetValueAtIndex (sys->p_cred->whitelist, i); CFDictionaryRef dict = CFArrayGetValueAtIndex(sys->p_cred->whitelist, i);
CFStringRef knownHost = (CFStringRef)CFDictionaryGetValue (dict, cfKeyHost); CFStringRef knownHost = (CFStringRef)CFDictionaryGetValue(dict, cfKeyHost);
SecCertificateRef knownCert = (SecCertificateRef)CFDictionaryGetValue (dict, cfKeyCertificate); SecCertificateRef knownCert = (SecCertificateRef)CFDictionaryGetValue(dict, cfKeyCertificate);
if (!knownHost || !knownCert) if (!knownHost || !knownCert)
continue; continue;
if (CFEqual (knownHost, cfHostname) && CFEqual (knownCert, leaf_cert)) { if (CFEqual(knownHost, cfHostname) && CFEqual(knownCert, leaf_cert)) {
msg_Warn(session, "certificate already accepted, continuing"); msg_Warn(session, "certificate already accepted, continuing");
result = 0; result = 0;
goto out; goto out;
...@@ -331,27 +331,27 @@ static int st_validateServerCertificate (vlc_tls_t *session, const char *hostnam ...@@ -331,27 +331,27 @@ static int st_validateServerCertificate (vlc_tls_t *session, const char *hostnam
"This problem may be caused by a configuration error " "This problem may be caused by a configuration error "
"or an attempt to breach your security or your privacy.\n\n" "or an attempt to breach your security or your privacy.\n\n"
"If in doubt, abort now.\n"); "If in doubt, abort now.\n");
int answer = dialog_Question (session, _("Insecure site"), vlc_gettext (msg), int answer = dialog_Question(session, _("Insecure site"), vlc_gettext (msg),
_("Abort"), _("Accept certificate temporarily"), NULL, hostname); _("Abort"), _("Accept certificate temporarily"), NULL, hostname);
if(answer == 2) { if (answer == 2) {
msg_Warn(session, "Proceeding despite of failed certificate validation"); msg_Warn(session, "Proceeding despite of failed certificate validation");
/* save leaf certificate in whitelist */ /* save leaf certificate in whitelist */
const void *keys[] = {cfKeyHost, cfKeyCertificate}; const void *keys[] = {cfKeyHost, cfKeyCertificate};
const void *values[] = {cfHostname, leaf_cert}; const void *values[] = {cfHostname, leaf_cert};
CFDictionaryRef dict = CFDictionaryCreate (kCFAllocatorDefault, CFDictionaryRef dict = CFDictionaryCreate(kCFAllocatorDefault,
keys, values, 2, keys, values, 2,
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks); &kCFTypeDictionaryValueCallBacks);
if(!dict) { if (!dict) {
msg_Err (session, "error creating dict"); msg_Err(session, "error creating dict");
result = -1; result = -1;
goto out; goto out;
} }
CFArrayAppendValue (sys->p_cred->whitelist, dict); CFArrayAppendValue(sys->p_cred->whitelist, dict);
CFRelease (dict); CFRelease(dict);
result = 0; result = 0;
goto out; goto out;
...@@ -362,12 +362,12 @@ static int st_validateServerCertificate (vlc_tls_t *session, const char *hostnam ...@@ -362,12 +362,12 @@ static int st_validateServerCertificate (vlc_tls_t *session, const char *hostnam
} }
out: out:
CFRelease (trust); CFRelease(trust);
if (cfHostname) if (cfHostname)
CFRelease (cfHostname); CFRelease(cfHostname);
if (leaf_cert) if (leaf_cert)
CFRelease (leaf_cert); CFRelease(leaf_cert);
return result; return result;
} }
...@@ -400,7 +400,7 @@ static int st_Handshake (vlc_tls_t *session, const char *host, ...@@ -400,7 +400,7 @@ static int st_Handshake (vlc_tls_t *session, const char *host,
return 0; return 0;
case errSSLServerAuthCompleted: case errSSLServerAuthCompleted:
return st_Handshake (session, host, service); return st_Handshake(session, host, service);
case errSSLConnectionRefused: case errSSLConnectionRefused:
msg_Err(session, "connection was refused"); msg_Err(session, "connection was refused");
...@@ -483,7 +483,7 @@ static int st_Recv (void *opaque, void *buf, size_t length) ...@@ -483,7 +483,7 @@ static int st_Recv (void *opaque, void *buf, size_t length)
size_t actualSize; size_t actualSize;
OSStatus ret = SSLRead(sys->p_context, buf, length, &actualSize); OSStatus ret = SSLRead(sys->p_context, buf, length, &actualSize);
if(ret == errSSLWouldBlock && actualSize) if (ret == errSSLWouldBlock && actualSize)
return actualSize; return actualSize;
/* peer performed shutdown */ /* peer performed shutdown */
...@@ -516,12 +516,12 @@ static void st_SessionClose (vlc_tls_creds_t *crd, vlc_tls_t *session) { ...@@ -516,12 +516,12 @@ static void st_SessionClose (vlc_tls_creds_t *crd, vlc_tls_t *session) {
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
CFRelease(sys->p_context); CFRelease(sys->p_context);
#else #else
if(SSLDisposeContext(sys->p_context) != noErr) { if (SSLDisposeContext(sys->p_context) != noErr) {
msg_Err(session, "error deleting context"); msg_Err(session, "error deleting context");
} }
#endif #endif
} }
free (sys); free(sys);
} }
/** /**
...@@ -531,7 +531,7 @@ static void st_SessionClose (vlc_tls_creds_t *crd, vlc_tls_t *session) { ...@@ -531,7 +531,7 @@ static void st_SessionClose (vlc_tls_creds_t *crd, vlc_tls_t *session) {
static int st_SessionOpenCommon (vlc_tls_creds_t *crd, vlc_tls_t *session, static int st_SessionOpenCommon (vlc_tls_creds_t *crd, vlc_tls_t *session,
int fd, bool b_server) { int fd, bool b_server) {
vlc_tls_sys_t *sys = malloc (sizeof (*session->sys)); vlc_tls_sys_t *sys = malloc(sizeof(*session->sys));
if (unlikely(sys == NULL)) if (unlikely(sys == NULL))
return VLC_ENOMEM; return VLC_ENOMEM;
...@@ -564,14 +564,14 @@ static int st_SessionOpenCommon (vlc_tls_creds_t *crd, vlc_tls_t *session, ...@@ -564,14 +564,14 @@ static int st_SessionOpenCommon (vlc_tls_creds_t *crd, vlc_tls_t *session,
sys->p_context = p_context; sys->p_context = p_context;
OSStatus ret = SSLSetIOFuncs (p_context, st_SocketReadFunc, st_SocketWriteFunc); OSStatus ret = SSLSetIOFuncs(p_context, st_SocketReadFunc, st_SocketWriteFunc);
if(ret != noErr) { if (ret != noErr) {
msg_Err(session, "cannot set io functions"); msg_Err(session, "cannot set io functions");
return -1; return -1;
} }
ret = SSLSetConnection (p_context, session); ret = SSLSetConnection(p_context, session);
if(ret != noErr) { if (ret != noErr) {
msg_Err(session, "cannot set connection"); msg_Err(session, "cannot set connection");
return -1; return -1;
} }
...@@ -601,16 +601,16 @@ static int st_ClientSessionOpen (vlc_tls_creds_t *crd, vlc_tls_t *session, ...@@ -601,16 +601,16 @@ static int st_ClientSessionOpen (vlc_tls_creds_t *crd, vlc_tls_t *session,
certificates */ certificates */
/* this has effect only on iOS 5 and OSX 10.8 or later ... */ /* this has effect only on iOS 5 and OSX 10.8 or later ... */
ret = SSLSetSessionOption (sys->p_context, kSSLSessionOptionBreakOnServerAuth, true); ret = SSLSetSessionOption(sys->p_context, kSSLSessionOptionBreakOnServerAuth, true);
if(ret != noErr) { if (ret != noErr) {
msg_Err (session, "cannot set session option"); msg_Err (session, "cannot set session option");
goto error; goto error;
} }
#if !TARGET_OS_IPHONE #if !TARGET_OS_IPHONE
/* ... thus calling this for earlier osx versions, which is not available on iOS in turn */ /* ... thus calling this for earlier osx versions, which is not available on iOS in turn */
ret = SSLSetEnableCertVerify (sys->p_context, false); ret = SSLSetEnableCertVerify(sys->p_context, false);
if(ret != noErr) { if (ret != noErr) {
msg_Err (session, "error setting enable cert verify"); msg_Err(session, "error setting enable cert verify");
goto error; goto error;
} }
#endif #endif
...@@ -651,7 +651,7 @@ static void CloseClient (vlc_tls_creds_t *crd) { ...@@ -651,7 +651,7 @@ static void CloseClient (vlc_tls_creds_t *crd) {
if (sys->whitelist) if (sys->whitelist)
CFRelease(sys->whitelist); CFRelease(sys->whitelist);
free (sys); free(sys);
} }
/* Begin of server-side methods */ /* Begin of server-side methods */
...@@ -718,14 +718,14 @@ static int OpenServer (vlc_tls_creds_t *crd, const char *cert, const char *key) ...@@ -718,14 +718,14 @@ static int OpenServer (vlc_tls_creds_t *crd, const char *cert, const char *key)
ret = SecKeychainSearchCreateFromAttributes(NULL, kSecCertificateItemClass, ret = SecKeychainSearchCreateFromAttributes(NULL, kSecCertificateItemClass,
&attrList, &searchReference); &attrList, &searchReference);
if (ret != noErr || searchReference == NULL) { if (ret != noErr || searchReference == NULL) {
msg_Err (crd, "Cannot find certificate with alias %s", cert); msg_Err(crd, "Cannot find certificate with alias %s", cert);
return VLC_EGENERIC; return VLC_EGENERIC;
} }
SecKeychainItemRef itemRef = NULL; SecKeychainItemRef itemRef = NULL;
ret = SecKeychainSearchCopyNext(searchReference, &itemRef); ret = SecKeychainSearchCopyNext(searchReference, &itemRef);
if (ret != noErr) { if (ret != noErr) {
msg_Err (crd, "Cannot get certificate with alias %s, error: %d", cert, ret); msg_Err(crd, "Cannot get certificate with alias %s, error: %d", cert, ret);
return VLC_EGENERIC; return VLC_EGENERIC;
} }
CFRelease(searchReference); CFRelease(searchReference);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment