mirror of https://github.com/shred/acme4j
Accept String IP for convenience
parent
548fa4db5e
commit
710d2ca948
|
@ -112,6 +112,22 @@ public class Identifier implements Serializable {
|
||||||
return new Identifier(TYPE_IP, ip.getHostAddress());
|
return new Identifier(TYPE_IP, ip.getHostAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new IP identifier for the given {@link InetAddress}.
|
||||||
|
*
|
||||||
|
* @param ip
|
||||||
|
* IP address as {@link String}
|
||||||
|
* @return New {@link Identifier}
|
||||||
|
* @since 2.7
|
||||||
|
*/
|
||||||
|
public static Identifier ip(String ip) {
|
||||||
|
try {
|
||||||
|
return ip(InetAddress.getByName(ip));
|
||||||
|
} catch (UnknownHostException ex) {
|
||||||
|
throw new IllegalArgumentException("Bad IP: " + ip, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the identifier type.
|
* Returns the identifier type.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -88,6 +88,11 @@ public class IdentifierTest {
|
||||||
assertThat(id2.getType(), is(Identifier.TYPE_IP));
|
assertThat(id2.getType(), is(Identifier.TYPE_IP));
|
||||||
assertThat(id2.getValue(), is("2001:db8:85a3:0:0:8a2e:370:7334"));
|
assertThat(id2.getValue(), is("2001:db8:85a3:0:0:8a2e:370:7334"));
|
||||||
assertThat(id2.getIP().getHostAddress(), is("2001:db8:85a3:0:0:8a2e:370:7334"));
|
assertThat(id2.getIP().getHostAddress(), is("2001:db8:85a3:0:0:8a2e:370:7334"));
|
||||||
|
|
||||||
|
Identifier id3 = Identifier.ip("192.168.2.99");
|
||||||
|
assertThat(id3.getType(), is(Identifier.TYPE_IP));
|
||||||
|
assertThat(id3.getValue(), is("192.168.2.99"));
|
||||||
|
assertThat(id3.getIP().getHostAddress(), is("192.168.2.99"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = AcmeProtocolException.class)
|
@Test(expected = AcmeProtocolException.class)
|
||||||
|
|
|
@ -178,17 +178,19 @@ _acme4j_ supports the [ACME IP](https://tools.ietf.org/html/draft-ietf-acme-ip)
|
||||||
```java
|
```java
|
||||||
Order order = account.newOrder()
|
Order order = account.newOrder()
|
||||||
.identifier(Identifier.ip(InetAddress.getByName("192.168.1.2")))
|
.identifier(Identifier.ip(InetAddress.getByName("192.168.1.2")))
|
||||||
|
.identifier(Identifier.ip("192.168.2.3")) // for your convenience
|
||||||
.identifier(Identifier.dns("example.org"))
|
.identifier(Identifier.dns("example.org"))
|
||||||
.create();
|
.create();
|
||||||
```
|
```
|
||||||
|
|
||||||
The example also shows how to add domain names as DNS `Identifier` objects. Adding domain names via `domain()` is just a shortcut notation for it.
|
The example also shows how to add domain names as DNS `Identifier` objects. Adding domain names via `domain()` is just a shortcut notation for it.
|
||||||
|
|
||||||
The `CSRBuilder` also accepts IP addresses for generating the CSR:
|
The `CSRBuilder` also accepts IP addresses and `Identifier` for generating the CSR:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
CSRBuilder csrb = new CSRBuilder();
|
CSRBuilder csrb = new CSRBuilder();
|
||||||
csrb.addIP(InetAddress.getByName("192.168.1.2"));
|
csrb.addIP(InetAddress.getByName("192.168.1.2"));
|
||||||
|
csrb.addIdentifier(Identifier.ip("192.168.2.3"));
|
||||||
csrb.sign(domainKeyPair);
|
csrb.sign(domainKeyPair);
|
||||||
byte[] csr = csrb.getEncoded();
|
byte[] csr = csrb.getEncoded();
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in New Issue