@Test public void testAddCertificateAuthorityAssertsMaxLength() { CertificateRequest req = new CertificateRequest(peerAddress); X500Principal authority = new X500Principal("O=Eclipse, OU=Hono Project, CN=test"); int encodedLength = 2 + authority.getEncoded().length; int maxLength = (1 << 16) - 1; int maxNoOfAuthorities = (int) Math.floor(maxLength / encodedLength); for (int i = 0; i < maxNoOfAuthorities; i++) { assertTrue(req.addCertificateAuthority(authority)); } assertFalse(req.addCertificateAuthority(authority)); }
public boolean addCertificateAuthority(X500Principal authority) { if (authority == null) { throw new NullPointerException("authority must not be null"); } int encodedAuthorityLength = (CERTIFICATE_AUTHORITY_LENGTH_BITS / Byte.SIZE) + authority.getEncoded().length; if (certificateAuthoritiesEncodedLength + encodedAuthorityLength <= MAX_LENGTH_CERTIFICATE_AUTHORITIES) { certificateAuthorities.add(authority); certificateAuthoritiesEncodedLength += encodedAuthorityLength; return true; } else { return false; } }
CertificateRequest extends HandshakeMessage { public boolean addCertificateAuthority(X500Principal authority) { if (authority == null) { throw new NullPointerException("authority must not be null"); } int encodedAuthorityLength = (CERTIFICATE_AUTHORITY_LENGTH_BITS / Byte.SIZE) + authority.getEncoded().length; if (certificateAuthoritiesEncodedLength + encodedAuthorityLength <= MAX_LENGTH_CERTIFICATE_AUTHORITIES) { certificateAuthorities.add(authority); certificateAuthoritiesEncodedLength += encodedAuthorityLength; return true; } else { return false; } } }
CertificateRequest extends HandshakeMessage { public boolean addCertificateAuthority(X500Principal authority) { if (authority == null) { throw new NullPointerException("authority must not be null"); } int encodedAuthorityLength = (CERTIFICATE_AUTHORITY_LENGTH_BITS / Byte.SIZE) + authority.getEncoded().length; if (certificateAuthoritiesEncodedLength + encodedAuthorityLength <= MAX_LENGTH_CERTIFICATE_AUTHORITIES) { certificateAuthorities.add(authority); certificateAuthoritiesEncodedLength += encodedAuthorityLength; return true; } else { return false; } } CertificateRequest(InetSocketAddress peerAddress);  CertificateRequest(
			List<ClientCertificateType> certificateTypes,
			List<SignatureAndHashAlgorithm> supportedSignatureAlgorithms,
			List<X500Principal> certificateAuthorities,
			InetSocketAddress peerAddress); }
CertificateRequest extends HandshakeMessage { public boolean addCertificateAuthority(X500Principal authority) { if (authority == null) { throw new NullPointerException("authority must not be null"); } int encodedAuthorityLength = (CERTIFICATE_AUTHORITY_LENGTH_BITS / Byte.SIZE) + authority.getEncoded().length; if (certificateAuthoritiesEncodedLength + encodedAuthorityLength <= MAX_LENGTH_CERTIFICATE_AUTHORITIES) { certificateAuthorities.add(authority); certificateAuthoritiesEncodedLength += encodedAuthorityLength; return true; } else { return false; } } CertificateRequest(InetSocketAddress peerAddress);  CertificateRequest(
			List<ClientCertificateType> certificateTypes,
			List<SignatureAndHashAlgorithm> supportedSignatureAlgorithms,
			List<X500Principal> certificateAuthorities,
			InetSocketAddress peerAddress); @Override HandshakeType getMessageType(); @Override int getMessageLength(); @Override String toString(); @Override byte[] fragmentToByteArray(); static HandshakeMessage fromReader(DatagramReader reader, InetSocketAddress peerAddress); void addCertificateType(ClientCertificateType certificateType); void addSignatureAlgorithm(SignatureAndHashAlgorithm signatureAndHashAlgorithm); void addSignatureAlgorithms(List<SignatureAndHashAlgorithm> signatureAndHashAlgorithms); void selectSignatureAlgorithms(List<SignatureAndHashAlgorithm> supportedSignatureAndHashAlgorithms); boolean addCertificateAuthority(X500Principal authority); boolean addCerticiateAuthorities(List<X500Principal> authorities); List<ClientCertificateType> getCertificateTypes(); SignatureAndHashAlgorithm getSignatureAndHashAlgorithm(PublicKey key); SignatureAndHashAlgorithm getSignatureAndHashAlgorithm(List<X509Certificate> chain); List<SignatureAndHashAlgorithm> getSupportedSignatureAlgorithms(); List<X500Principal> getCertificateAuthorities(); }
CertificateRequest extends HandshakeMessage { public boolean addCertificateAuthority(X500Principal authority) { if (authority == null) { throw new NullPointerException("authority must not be null"); } int encodedAuthorityLength = (CERTIFICATE_AUTHORITY_LENGTH_BITS / Byte.SIZE) + authority.getEncoded().length; if (certificateAuthoritiesEncodedLength + encodedAuthorityLength <= MAX_LENGTH_CERTIFICATE_AUTHORITIES) { certificateAuthorities.add(authority); certificateAuthoritiesEncodedLength += encodedAuthorityLength; return true; } else { return false; } } CertificateRequest(InetSocketAddress peerAddress);  CertificateRequest(
			List<ClientCertificateType> certificateTypes,
			List<SignatureAndHashAlgorithm> supportedSignatureAlgorithms,
			List<X500Principal> certificateAuthorities,
			InetSocketAddress peerAddress); @Override HandshakeType getMessageType(); @Override int getMessageLength(); @Override String toString(); @Override byte[] fragmentToByteArray(); static HandshakeMessage fromReader(DatagramReader reader, InetSocketAddress peerAddress); void addCertificateType(ClientCertificateType certificateType); void addSignatureAlgorithm(SignatureAndHashAlgorithm signatureAndHashAlgorithm); void addSignatureAlgorithms(List<SignatureAndHashAlgorithm> signatureAndHashAlgorithms); void selectSignatureAlgorithms(List<SignatureAndHashAlgorithm> supportedSignatureAndHashAlgorithms); boolean addCertificateAuthority(X500Principal authority); boolean addCerticiateAuthorities(List<X500Principal> authorities); List<ClientCertificateType> getCertificateTypes(); SignatureAndHashAlgorithm getSignatureAndHashAlgorithm(PublicKey key); SignatureAndHashAlgorithm getSignatureAndHashAlgorithm(List<X509Certificate> chain); List<SignatureAndHashAlgorithm> getSupportedSignatureAlgorithms(); List<X500Principal> getCertificateAuthorities();  }