@breakside/jskit 2023.19.0 → 2023.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Frameworks/DOM.jsframework/Info.json +2 -2
- package/Frameworks/DOM.jsframework/io.breakside.JSKit.DOM-bundle.js +2 -2
- package/Frameworks/FontKit.jsframework/Info.json +2 -2
- package/Frameworks/FontKit.jsframework/io.breakside.JSKit.FontKit-bundle.js +2 -2
- package/Frameworks/Foundation.jsframework/Info.json +2 -2
- package/Frameworks/Foundation.jsframework/JS/JSURLResponse.js +1 -1
- package/Frameworks/Foundation.jsframework/io.breakside.JSKit.Foundation-bundle.js +2 -2
- package/Frameworks/SecurityKit.jsframework/Info.json +2 -2
- package/Frameworks/SecurityKit.jsframework/JS/SECCipher+HTML.js +31 -44
- package/Frameworks/SecurityKit.jsframework/JS/SECCipher+Node.js +16 -38
- package/Frameworks/SecurityKit.jsframework/JS/SECCipher.js +33 -3
- package/Frameworks/SecurityKit.jsframework/JS/SECHMAC.js +17 -0
- package/Frameworks/SecurityKit.jsframework/io.breakside.JSKit.SecurityKit-bundle.js +2 -2
- package/Info.json +2 -2
- package/Node/HTMLBuilder.js +76 -20
- package/Node/io.breakside.jskit-bundle.js +2 -2
- package/Root/Frameworks/APIKit/Info.yaml +1 -1
- package/Root/Frameworks/APIKitTesting/Info.yaml +1 -1
- package/Root/Frameworks/AuthKit/Info.yaml +1 -1
- package/Root/Frameworks/CSSOM/Info.yaml +1 -1
- package/Root/Frameworks/ChartKit/Info.yaml +1 -1
- package/Root/Frameworks/ConferenceKit/Info.yaml +1 -1
- package/Root/Frameworks/DBKit/Info.yaml +1 -1
- package/Root/Frameworks/DOM/Info.yaml +1 -1
- package/Root/Frameworks/Dispatch/Info.yaml +1 -1
- package/Root/Frameworks/FontKit/Info.yaml +1 -1
- package/Root/Frameworks/Foundation/Info.yaml +1 -1
- package/Root/Frameworks/Foundation/JSURLResponse.js +1 -1
- package/Root/Frameworks/ImageKit/Info.yaml +1 -1
- package/Root/Frameworks/MediaKit/Info.yaml +1 -1
- package/Root/Frameworks/MediaKitUI/Info.yaml +1 -1
- package/Root/Frameworks/NotificationKit/Info.yaml +2 -1
- package/Root/Frameworks/NotificationKit/NKHTMLUserNotificationCenter.js +59 -18
- package/Root/Frameworks/NotificationKit/NKUserNotification.js +12 -1
- package/Root/Frameworks/NotificationKit/NKUserNotificationCenter.js +5 -0
- package/Root/Frameworks/NotificationKit/NKWebPushService.js +145 -38
- package/Root/Frameworks/NotificationKit/NotificationKit+Node.js +19 -0
- package/Root/Frameworks/PDFKit/Info.yaml +1 -1
- package/Root/Frameworks/QRKit/Info.yaml +1 -1
- package/Root/Frameworks/SearchKit/Info.yaml +1 -1
- package/Root/Frameworks/SecurityKit/Info.yaml +1 -1
- package/Root/Frameworks/SecurityKit/SECCipher+HTML.js +31 -44
- package/Root/Frameworks/SecurityKit/SECCipher+Node.js +16 -38
- package/Root/Frameworks/SecurityKit/SECCipher.js +33 -3
- package/Root/Frameworks/SecurityKit/SECHMAC.js +17 -0
- package/Root/Frameworks/ServerKit/Info.yaml +1 -1
- package/Root/Frameworks/ServerKitTesting/Info.yaml +1 -1
- package/Root/Frameworks/TestKit/Info.yaml +1 -1
- package/Root/Frameworks/UIKit/Info.yaml +1 -1
- package/Root/Frameworks/UIKit/UIHTMLContentEditableTextInputManager.js +1 -1
- package/Root/Frameworks/UIKit/UIHTMLWindowServer.js +8 -1
- package/Root/Frameworks/UIKit/UIMenuView.js +4 -0
- package/Root/Frameworks/UIKit/UIWindowServer.js +7 -13
- package/Root/Frameworks/UIKitTesting/Info.yaml +1 -1
- package/Root/Templates/html/${PROJECT_NAME}/www/${PROJECT_NAME}.webmanifest +9 -0
- package/Root/Templates/html/${PROJECT_NAME}/www/HTMLAppBootstrapper.js +7 -1
- package/Root/Templates/html/${PROJECT_NAME}/www/index.html +1 -0
- package/Root/Templates/html/${PROJECT_NAME}/www/service-worker.js +25 -1
- package/package.json +1 -1
|
@@ -3,14 +3,14 @@ JSBundle.bundles['io.breakside.jskit'] = {
|
|
|
3
3
|
"Info": {
|
|
4
4
|
"JSBundleType": "node",
|
|
5
5
|
"JSBundleIdentifier": "io.breakside.jskit",
|
|
6
|
-
"JSBundleVersion": "2023.
|
|
6
|
+
"JSBundleVersion": "2023.21.0",
|
|
7
7
|
"JSExecutableName": "jskit",
|
|
8
8
|
"NPMOrganization": "breakside",
|
|
9
9
|
"JSResources": [
|
|
10
10
|
"Tests/HTMLTestRunner.js",
|
|
11
11
|
"Tests/NodeTestRunner.js"
|
|
12
12
|
],
|
|
13
|
-
"GitRevision": "
|
|
13
|
+
"GitRevision": "af89e2c41e4ddad1c493c9ccfd577f76dde0520b"
|
|
14
14
|
},
|
|
15
15
|
"Resources": [
|
|
16
16
|
{
|
|
@@ -175,7 +175,7 @@ JSURLResponse.error = function(statusCode, object){
|
|
|
175
175
|
|
|
176
176
|
JSGlobalObject.JSURLResponseError = function(response){
|
|
177
177
|
if (this === undefined){
|
|
178
|
-
return new JSURLResponseError();
|
|
178
|
+
return new JSURLResponseError(response);
|
|
179
179
|
}
|
|
180
180
|
this.name = "JSURLResponseError";
|
|
181
181
|
if (response instanceof JSURLResponseError){
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
JSBundleType: framework
|
|
2
2
|
JSBundleIdentifier: io.breakside.JSKit.NotificationKit
|
|
3
|
-
JSBundleVersion: 2023.
|
|
3
|
+
JSBundleVersion: 2023.21.0
|
|
4
4
|
JSDevelopmentLanguage: en
|
|
5
5
|
JSCopyright: Copyright © 2021 Breakside Inc.
|
|
6
6
|
JSBundleEnvironments:
|
|
7
7
|
html: NotificationKit+HTML.js
|
|
8
|
+
node: NotificationKit+Node.js
|
|
8
9
|
JSLicenseNotice: |
|
|
9
10
|
Licensed under the Breakside Public License, Version 1.0 (the "License");
|
|
10
11
|
you may not use this file except in compliance with the License.
|
|
@@ -35,44 +35,85 @@ JSClass("NKHTMLUserNotificationCenter", NKUserNotificationCenter, {
|
|
|
35
35
|
domDocument: null,
|
|
36
36
|
serviceWorkerContainer: null,
|
|
37
37
|
|
|
38
|
-
registerForRemoteNotifications: function(
|
|
38
|
+
registerForRemoteNotifications: function(completion, target){
|
|
39
39
|
if (!completion){
|
|
40
|
-
completion = Promise.completion();
|
|
40
|
+
completion = Promise.completion(Promise.rejectNonNullSecondArgument);
|
|
41
41
|
}
|
|
42
42
|
if (this.serviceWorkerContainer === null){
|
|
43
|
-
|
|
44
|
-
JSRunLoop.main.schedule(completion, target, null);
|
|
43
|
+
JSRunLoop.main.schedule(completion, target, null, new Error("Remote notifications not supported on this device (no service workers)"));
|
|
45
44
|
}else{
|
|
45
|
+
var notificationCenter = this;
|
|
46
46
|
this.serviceWorkerContainer.getRegistration().then(function(serviceWorkerRegistration){
|
|
47
47
|
if (!serviceWorkerRegistration){
|
|
48
|
-
|
|
49
|
-
completion.call(target, null);
|
|
48
|
+
completion.call(target, null, new Error("Missing service worker registration"));
|
|
50
49
|
return;
|
|
51
50
|
}
|
|
52
51
|
if (!serviceWorkerRegistration.pushManager){
|
|
53
|
-
|
|
54
|
-
completion.call(target, null);
|
|
52
|
+
completion.call(target, null, new Error("Remote notifications not supported on this device (no push manager)"));
|
|
55
53
|
return;
|
|
56
54
|
}
|
|
57
|
-
var options = {
|
|
58
|
-
|
|
55
|
+
var options = {
|
|
56
|
+
userVisibleOnly: true
|
|
57
|
+
};
|
|
58
|
+
if (notificationCenter.webPushApplicationServerJWK){
|
|
59
59
|
options.applicationServerKey = JSData.initWithChunks([
|
|
60
60
|
JSData.initWithArray([0x04]),
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
notificationCenter.webPushApplicationServerJWK.x.dataByDecodingBase64URL(),
|
|
62
|
+
notificationCenter.webPushApplicationServerJWK.y.dataByDecodingBase64URL()
|
|
63
63
|
]).base64URLStringRepresentation();
|
|
64
64
|
}
|
|
65
65
|
serviceWorkerRegistration.pushManager.subscribe(options).then(function(subscription){
|
|
66
66
|
var registration = {
|
|
67
67
|
type: NKUserNotificationCenter.RegistrationType.web,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
options: {
|
|
69
|
+
applicationServerJWK: notificationCenter.webPushApplicationServerJWK,
|
|
70
|
+
},
|
|
71
|
+
subscription: {
|
|
72
|
+
endpoint: subscription.endpoint,
|
|
73
|
+
expirationTime: subscription.expirationTime,
|
|
74
|
+
keys: {
|
|
75
|
+
p256dh: JSData.initWithBuffer(subscription.getKey("p256dh")).base64URLStringRepresentation(),
|
|
76
|
+
auth: JSData.initWithBuffer(subscription.getKey("auth")).base64URLStringRepresentation()
|
|
77
|
+
},
|
|
78
|
+
}
|
|
71
79
|
};
|
|
72
|
-
completion.call(target, registration);
|
|
80
|
+
completion.call(target, registration, null);
|
|
81
|
+
}, function(error){
|
|
82
|
+
completion.call(target, null, error);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return completion.promise;
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
unregisterForRemoteNotifications: function(completion, target){
|
|
90
|
+
if (!completion){
|
|
91
|
+
completion = Promise.completion(Promise.rejectNonNullFirstArgument);
|
|
92
|
+
}
|
|
93
|
+
if (this.serviceWorkerContainer === null){
|
|
94
|
+
JSRunLoop.main.schedule(completion, target, new Error("Remote notifications not supported on this device (no service workers)"));
|
|
95
|
+
}else{
|
|
96
|
+
this.serviceWorkerContainer.getRegistration().then(function(serviceWorkerRegistration){
|
|
97
|
+
if (!serviceWorkerRegistration){
|
|
98
|
+
completion.call(target, new Error("Missing service worker registration"));
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (!serviceWorkerRegistration.pushManager){
|
|
102
|
+
completion.call(target, new Error("Remote notifications not supported on this device (no push manager)"));
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
serviceWorkerRegistration.pushManager.getSubscription().then(function(subscription){
|
|
106
|
+
if (subscription){
|
|
107
|
+
subscription.unsubscribe(function(){
|
|
108
|
+
completion.call(target, null);
|
|
109
|
+
}, function(error){
|
|
110
|
+
completion.call(target, error);
|
|
111
|
+
});
|
|
112
|
+
}else{
|
|
113
|
+
completion.call(target, null);
|
|
114
|
+
}
|
|
73
115
|
}, function(error){
|
|
74
|
-
|
|
75
|
-
completion.call(target, null);
|
|
116
|
+
completion.call(target, error);
|
|
76
117
|
});
|
|
77
118
|
});
|
|
78
119
|
}
|
|
@@ -21,6 +21,8 @@ JSClass("NKUserNotification", JSObject, {
|
|
|
21
21
|
title: null,
|
|
22
22
|
body: null,
|
|
23
23
|
identifier: null,
|
|
24
|
+
timeToLive: 3600,
|
|
25
|
+
priority: 0,
|
|
24
26
|
|
|
25
27
|
initWithTitle: function(title, body){
|
|
26
28
|
this.title = title;
|
|
@@ -28,4 +30,13 @@ JSClass("NKUserNotification", JSObject, {
|
|
|
28
30
|
this.identifier = UUID();
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
NKUserNotification.Priority = {
|
|
36
|
+
|
|
37
|
+
normal: 0,
|
|
38
|
+
veryLow: 1,
|
|
39
|
+
low: 2,
|
|
40
|
+
high: 3,
|
|
41
|
+
|
|
42
|
+
};
|
|
@@ -36,6 +36,9 @@ JSClass("NKUserNotificationCenter", JSObject, {
|
|
|
36
36
|
registerForRemoteNotifications: function(completion, target){
|
|
37
37
|
},
|
|
38
38
|
|
|
39
|
+
unregisterForRemoteNotifications: function(completion, target){
|
|
40
|
+
},
|
|
41
|
+
|
|
39
42
|
addNotification: function(notification, date){
|
|
40
43
|
},
|
|
41
44
|
|
|
@@ -44,6 +47,8 @@ JSClass("NKUserNotificationCenter", JSObject, {
|
|
|
44
47
|
|
|
45
48
|
defaultIcon: null,
|
|
46
49
|
|
|
50
|
+
webPushApplicationServerJWK: null,
|
|
51
|
+
|
|
47
52
|
});
|
|
48
53
|
|
|
49
54
|
NKUserNotificationCenter.AuthorizationStatus = {
|
|
@@ -15,91 +15,198 @@
|
|
|
15
15
|
|
|
16
16
|
// #import Foundation
|
|
17
17
|
// #import SecurityKit
|
|
18
|
-
//
|
|
18
|
+
// #import "NKUserNotification.js"
|
|
19
|
+
/* global NKWebPushService */
|
|
19
20
|
"use strict";
|
|
20
21
|
|
|
21
22
|
(function(){
|
|
22
23
|
|
|
23
24
|
var logger = JSLog("notify", "webpush");
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
JSClass("NKWebPushService", JSObject, {
|
|
26
27
|
|
|
27
|
-
url: null,
|
|
28
28
|
urlSession: null,
|
|
29
|
-
|
|
29
|
+
keystore: null,
|
|
30
30
|
contactURL: null,
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
this.
|
|
32
|
+
initWithKeystore: function(keystore, urlSession){
|
|
33
|
+
this.keystore = keystore;
|
|
34
34
|
this.urlSession = urlSession || JSURLSession.shared;
|
|
35
35
|
},
|
|
36
36
|
|
|
37
|
-
pushNotification: function(notification, completion, target){
|
|
37
|
+
pushNotification: function(notification, registration, completion, target){
|
|
38
38
|
if (!completion){
|
|
39
|
-
completion = Promise.completion(Promise.
|
|
39
|
+
completion = Promise.completion(Promise.resolveNull);
|
|
40
40
|
}
|
|
41
|
-
this.createPushRequest(function(request){
|
|
42
|
-
if (
|
|
43
|
-
completion.call(target,
|
|
41
|
+
this.createPushRequest(notification, registration, function(request, error){
|
|
42
|
+
if (error !== null){
|
|
43
|
+
completion.call(target, error);
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
46
|
var task = this.urlSession.dataTaskWithRequest(request, function(error){
|
|
47
47
|
if (error !== null){
|
|
48
48
|
logger.error("Push request failed: %{error}", error);
|
|
49
|
-
completion.call(target,
|
|
49
|
+
completion.call(target, error);
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
52
|
if (task.response.statusCode !== JSURLResponse.StatusCode.created){
|
|
53
53
|
logger.error("Push request failed with %d", task.response.statusCode);
|
|
54
|
-
completion.call(target,
|
|
54
|
+
completion.call(target, JSURLResponseError(task.response));
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
|
-
completion.call(target,
|
|
57
|
+
completion.call(target, null);
|
|
58
58
|
});
|
|
59
|
+
task.resume();
|
|
59
60
|
}, this);
|
|
60
61
|
return completion.promise;
|
|
61
62
|
},
|
|
62
63
|
|
|
63
|
-
createPushRequest: function(completion, target){
|
|
64
|
-
var
|
|
64
|
+
createPushRequest: function(notification, registration, completion, target){
|
|
65
|
+
var url = JSURL.initWithString(registration.subscription.endpoint);
|
|
66
|
+
var request = JSURLRequest.initWithURL(url);
|
|
65
67
|
request.method = JSURLRequest.Method.post;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
if (notification.identifier !== null){
|
|
69
|
+
var hash = JSSHA1Hash(notification.identifier.utf8());
|
|
70
|
+
request.headerMap.add("Topic", hash.base64URLStringRepresentation());
|
|
71
|
+
}
|
|
72
|
+
request.headerMap.add("TTL", notification.timeToLive);
|
|
73
|
+
request.headerMap.add("Urgency", this.urgencyForNotificationPriority(notification.priority));
|
|
74
|
+
this.authorizePushRequest(request, notification, registration, function(error){
|
|
75
|
+
if (error !== null){
|
|
76
|
+
completion.call(target, request, error);
|
|
77
|
+
return;
|
|
72
78
|
}
|
|
79
|
+
this.encodePushRequest(request, notification, registration, function(error){
|
|
80
|
+
completion.call(target, request, error);
|
|
81
|
+
}, this);
|
|
73
82
|
}, this);
|
|
74
83
|
},
|
|
75
84
|
|
|
76
|
-
authorizePushRequest: function(request, completion, target){
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
85
|
+
authorizePushRequest: function(request, notification, registration, completion, target){
|
|
86
|
+
// https://www.rfc-editor.org/rfc/rfc8292
|
|
87
|
+
var publicJWK = registration.options.applicationServerJWK;
|
|
88
|
+
var privateJWK = null;
|
|
89
|
+
if (publicJWK){
|
|
90
|
+
privateJWK = this.keystore.jwkForIdentifier(publicJWK.kid);
|
|
91
|
+
if (privateJWK === null){
|
|
92
|
+
completion.call(target, new Error("No key matching kid: %s".sprintf(publicJWK.kid)));
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (privateJWK){
|
|
97
|
+
var url = JSURL.initWithString(registration.subscription.endpoint);
|
|
98
|
+
var claims = {
|
|
99
|
+
aud: url.origin,
|
|
100
|
+
exp: Math.floor(JSDate.initWithTimeIntervalSinceNow(JSTimeInterval.hours(24)).timeIntervalSince1970),
|
|
83
101
|
};
|
|
84
102
|
if (this.contactURL !== null){
|
|
85
|
-
|
|
103
|
+
claims.sub = this.contactURL.encodedString;
|
|
86
104
|
}
|
|
87
|
-
var
|
|
88
|
-
|
|
89
|
-
var
|
|
105
|
+
var token = SECJSONWebToken.initWithPayload(claims);
|
|
106
|
+
token.sign(privateJWK, function(tokenString){
|
|
107
|
+
var encodedPublicKey = JSData.initWithChunks([
|
|
90
108
|
JSData.initWithArray([0x04]),
|
|
91
|
-
|
|
92
|
-
|
|
109
|
+
privateJWK.x.dataByDecodingBase64URL(),
|
|
110
|
+
privateJWK.y.dataByDecodingBase64URL()
|
|
93
111
|
]).base64URLStringRepresentation();
|
|
94
|
-
request.headerMap.add("Authorization", "vapid t=%s,k=%s".sprintf(
|
|
95
|
-
completion.call(target,
|
|
112
|
+
request.headerMap.add("Authorization", "vapid t=%s, k=%s".sprintf(tokenString, encodedPublicKey));
|
|
113
|
+
completion.call(target, null);
|
|
96
114
|
}, function(error){
|
|
97
115
|
logger.error("Failed to sign push request: %{error}", error);
|
|
98
|
-
completion.call(target,
|
|
116
|
+
completion.call(target, error);
|
|
99
117
|
});
|
|
118
|
+
}else{
|
|
119
|
+
completion.call(target, null);
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
encodePushRequest: function(request, notification, registration, completion, target){
|
|
124
|
+
// https://www.rfc-editor.org/rfc/rfc8188
|
|
125
|
+
// https://www.rfc-editor.org/rfc/rfc8291
|
|
126
|
+
var encodedClientPublicKey = registration.subscription.keys.p256dh;
|
|
127
|
+
var encodedClientAuthSecret = registration.subscription.keys.auth;
|
|
128
|
+
var plaintext = JSON.stringify({
|
|
129
|
+
type: "notification",
|
|
130
|
+
title: notification.title,
|
|
131
|
+
body: notification.body
|
|
132
|
+
}).utf8();
|
|
133
|
+
if (encodedClientPublicKey && encodedClientAuthSecret){
|
|
134
|
+
if (plaintext.length > NKWebPushService.maximumRecordSize - 17){
|
|
135
|
+
completion.call(target, new Error("Message too long for web push"));
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
var clientPublicKeyData = encodedClientPublicKey.dataByDecodingBase64URL();
|
|
139
|
+
var clientAuthSecretData = encodedClientAuthSecret.dataByDecodingBase64URL();
|
|
140
|
+
var salt = SECCipher.getRandomData(16);
|
|
141
|
+
var caughtError = null;
|
|
142
|
+
// TODO: abstract ECDH calls so they're not node-specific
|
|
143
|
+
var crypto = require("crypto");
|
|
144
|
+
var ecdh = crypto.createECDH('prime256v1');
|
|
145
|
+
ecdh.generateKeys();
|
|
146
|
+
var serverPublicKeyData = JSData.initWithNodeBuffer(ecdh.getPublicKey());
|
|
147
|
+
var sharedKeyData = JSData.initWithNodeBuffer(ecdh.computeSecret(clientPublicKeyData));
|
|
148
|
+
SECHMAC.digest(SECHMAC.Algorithm.sha256, clientAuthSecretData, sharedKeyData).then(function(prk){
|
|
149
|
+
return SECHMAC.digest(SECHMAC.Algorithm.sha256, prk, JSData.initWithChunks([
|
|
150
|
+
"WebPush: info\x00".utf8(),
|
|
151
|
+
clientPublicKeyData,
|
|
152
|
+
serverPublicKeyData,
|
|
153
|
+
JSData.initWithArray([0x01])
|
|
154
|
+
]));
|
|
155
|
+
}).then(function(ikm){
|
|
156
|
+
return SECHMAC.digest(SECHMAC.Algorithm.sha256, salt, ikm);
|
|
157
|
+
}).then(function(prk){
|
|
158
|
+
return Promise.all([
|
|
159
|
+
SECHMAC.digest(SECHMAC.Algorithm.sha256, prk, "Content-Encoding: aes128gcm\x00\x01".utf8()),
|
|
160
|
+
SECHMAC.digest(SECHMAC.Algorithm.sha256, prk, "Content-Encoding: nonce\x00\x01".utf8())
|
|
161
|
+
]);
|
|
162
|
+
}).then(function(keyAndNonce){
|
|
163
|
+
var keyData = keyAndNonce[0].subdataInRange(JSRange(0, 16));
|
|
164
|
+
var nonceData = keyAndNonce[1].subdataInRange(JSRange(0, 12));
|
|
165
|
+
var cipher = SECCipher.initWithAlgorithm(SECCipher.Algorithm.aesGCM, 128);
|
|
166
|
+
return cipher.createKeyWithData(keyData).then(function(key){
|
|
167
|
+
if (key === null){
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
return cipher.encryptWithNonce(nonceData, JSData.initWithChunks([plaintext, JSData.initWithArray([0x02])]), key);
|
|
171
|
+
});
|
|
172
|
+
}).then(function(encrypted){
|
|
173
|
+
var ciphertext = encrypted.subdataInRange(JSRange(12, encrypted.length - 12));
|
|
174
|
+
var header = JSData.initWithLength(5);
|
|
175
|
+
header.dataView().setUint32(0, NKWebPushService.maximumRecordSize);
|
|
176
|
+
header[4] = serverPublicKeyData.length;
|
|
177
|
+
request.headerMap.add("Content-Encoding", "aes128gcm");
|
|
178
|
+
request.data = JSData.initWithChunks([
|
|
179
|
+
salt,
|
|
180
|
+
header,
|
|
181
|
+
serverPublicKeyData,
|
|
182
|
+
ciphertext
|
|
183
|
+
]);
|
|
184
|
+
}).catch(function(error){
|
|
185
|
+
caughtError = error;
|
|
186
|
+
}).finally(function(){
|
|
187
|
+
completion.call(target, caughtError);
|
|
188
|
+
});
|
|
189
|
+
}else{
|
|
190
|
+
if (plaintext.length > NKWebPushService.maximumRecordSize - 17){
|
|
191
|
+
completion.call(target, new Error("Message too long for web push"));
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
request.data = plaintext;
|
|
195
|
+
completion.call(target, null);
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
|
|
199
|
+
urgencyForNotificationPriority: function(priority){
|
|
200
|
+
switch (priority){
|
|
201
|
+
case NKUserNotification.Priority.veryLow: return "very-low";
|
|
202
|
+
case NKUserNotification.Priority.low: return "low";
|
|
203
|
+
case NKUserNotification.Priority.high: return "high";
|
|
204
|
+
default: return "normal";
|
|
100
205
|
}
|
|
101
206
|
}
|
|
102
207
|
|
|
103
208
|
});
|
|
104
209
|
|
|
210
|
+
NKWebPushService.maximumRecordSize = 4096;
|
|
211
|
+
|
|
105
212
|
})();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright 2021 Breakside Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Breakside Public License, Version 1.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// If a copy of the License was not distributed with this file, you may
|
|
6
|
+
// obtain a copy at
|
|
7
|
+
//
|
|
8
|
+
// http://breakside.io/licenses/LICENSE-1.0.txt
|
|
9
|
+
//
|
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
// See the License for the specific language governing permissions and
|
|
14
|
+
// limitations under the License.
|
|
15
|
+
|
|
16
|
+
// #import "NotificationKit.js"
|
|
17
|
+
"use strict";
|
|
18
|
+
|
|
19
|
+
// #import "NKWebPushService.js"
|