Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 88ffbbf

Browse files
Simplified working version
1 parent 4a8a749 commit 88ffbbf

File tree

1 file changed

+5
-32
lines changed

1 file changed

+5
-32
lines changed

‎src/main/java/com/naturalprogrammer/demo/webpush/WebPushDemoApplication.java

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -39,33 +39,6 @@ public static class MySubscription {
3939
private String publicKey;
4040
private String auth;
4141

42-
/**
43-
* Returns the base64 encoded public key string as a byte[]
44-
*/
45-
public byte[] getKeyAsBytes() {
46-
return Base64.getDecoder().decode(publicKey);
47-
}
48-
49-
/**
50-
* Returns the base64 encoded auth string as a byte[]
51-
*/
52-
public byte[] getAuthAsBytes() {
53-
return Base64.getDecoder().decode(auth);
54-
}
55-
56-
/**
57-
* Returns the base64 encoded public key as a PublicKey object
58-
*/
59-
public PublicKey getUserPublicKey() throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException {
60-
61-
KeyFactory kf = KeyFactory.getInstance("ECDH", BouncyCastleProvider.PROVIDER_NAME);
62-
ECNamedCurveParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("secp256r1");
63-
ECPoint point = ecSpec.getCurve().decodePoint(getKeyAsBytes());
64-
ECPublicKeySpec pubSpec = new ECPublicKeySpec(point, ecSpec);
65-
66-
return kf.generatePublic(pubSpec);
67-
}
68-
6942
public String getNotificationEndPoint() {
7043
return notificationEndPoint;
7144
}
@@ -104,8 +77,8 @@ public static void main(String[] args) throws NoSuchProviderException, NoSuchAlg
10477
Security.addProvider(new BouncyCastleProvider());
10578
}
10679

107-
pushService.setPublicKey(Utils.loadPublicKey("BBYCxwATP2vVgw7mMPHJfT6bZrJP2iUV7OP_oxHzEcNFenrX66D8G34CdEmVULNg4WJXfjkeyT0AT9LwavpN8M4="));
108-
pushService.setPrivateKey(Utils.loadPrivateKey("AKYLHgp-aV3kOys9Oy6QgxNI6OGIlOB3G6kjGvhl57j_"));
80+
pushService.setPublicKey("BBYCxwATP2vVgw7mMPHJfT6bZrJP2iUV7OP_oxHzEcNFenrX66D8G34CdEmVULNg4WJXfjkeyT0AT9LwavpN8M4=");
81+
pushService.setPrivateKey("AKYLHgp-aV3kOys9Oy6QgxNI6OGIlOB3G6kjGvhl57j_");
10982

11083
SpringApplication.run(WebPushDemoApplication.class, args);
11184
}
@@ -123,14 +96,14 @@ public void unsubscribe(MySubscription subscription) {
12396
}
12497

12598
@PostMapping("/notify-all")
126-
public byte[] notifyAll(@RequestBody byte[] message) throws GeneralSecurityException, IOException, JoseException, ExecutionException, InterruptedException {
99+
public String notifyAll(@RequestBody String message) throws GeneralSecurityException, IOException, JoseException, ExecutionException, InterruptedException {
127100

128101
for (MySubscription subscription: subscriptions.values()) {
129102

130103
Notification notification = new Notification(
131104
subscription.getNotificationEndPoint(),
132-
subscription.getUserPublicKey(),
133-
subscription.getAuthAsBytes(),
105+
subscription.getPublicKey(),
106+
subscription.getAuth(),
134107
message);
135108

136109
pushService.send(notification);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /