ObjFW  Check-in [909ad7d8c8]

Overview
Comment:OFGnuTLSTLSStream: Use more error codes
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 909ad7d8c8d4d1813db820c7789dd2f9f9cc3161c146a5231f26e754cf7d296d
User & Date: js on 2024-11-12 00:29:08
Other Links: manifest | tags
Context
2024-11-12
00:29
Increase ObjFWTLS library version check-in: 8917ca0492 user: js tags: trunk
00:29
OFGnuTLSTLSStream: Use more error codes check-in: 909ad7d8c8 user: js tags: trunk
00:28
OFTLSStream: Add more error codes check-in: 448629661d user: js tags: trunk
Changes

Modified src/tls/OFGnuTLSTLSStream.m from [5ff0b3f552] to [49ed6aa948].

75
76
77
78
79
80
81















82
83
84
85
86
87
88
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







			return e.bytesWritten;

		return -1;
	}

	return length;
}

static OFTLSStreamErrorCode
certificateStatusToErrorCode(gnutls_certificate_status_t status)
{
	if (status & GNUTLS_CERT_UNEXPECTED_OWNER)
		return OFTLSStreamErrorCodeCertificateNameMismatch;
	if (status & GNUTLS_CERT_REVOKED)
		return OFTLSStreamErrorCodeCertificateRevoked;
	if (status & (GNUTLS_CERT_EXPIRED | GNUTLS_CERT_NOT_ACTIVATED))
		return OFTLSStreamErrorCodeCertificatedExpired;
	if (status & GNUTLS_CERT_SIGNER_NOT_FOUND)
		return OFTLSStreamErrorCodeCertificateIssuerUntrusted;

	return OFTLSStreamErrorCodeCertificateVerificationFailed;
}

+ (void)load
{
	if (OFTLSStreamImplementation == Nil)
		OFTLSStreamImplementation = self;
}

254
255
256
257
258
259
260
261







262
263
264
265
266


267
268
269
270
271
272
273
269
270
271
272
273
274
275

276
277
278
279
280
281
282
283
284
285
286

287
288
289
290
291
292
293
294
295







-
+
+
+
+
+
+
+




-
+
+







		[_delegate retain];
		objc_autoreleasePoolPop(pool);
		return;
	}

	if (status == GNUTLS_E_SUCCESS)
		_handshakeDone = true;
	else
	else {
		OFTLSStreamErrorCode errorCode = OFTLSStreamErrorCodeUnknown;

		if (status == GNUTLS_E_CERTIFICATE_VERIFICATION_ERROR)
			errorCode = certificateStatusToErrorCode(
			    gnutls_session_get_verify_cert_status(_session));

		/* FIXME: Map to better errors */
		exception = [OFTLSHandshakeFailedException
		    exceptionWithStream: self
				   host: host
			      errorCode: OFTLSStreamErrorCodeUnknown];
			      errorCode: errorCode];
	}

	if ([_delegate respondsToSelector:
	    @selector(stream:didPerformClientHandshakeWithHost:exception:)])
		[_delegate		       stream: self
		    didPerformClientHandshakeWithHost: host
					    exception: exception];