-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add registration for push notifications
- Loading branch information
John Newman
committed
Jun 28, 2024
1 parent
147c31a
commit 94bba61
Showing
9 changed files
with
219 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package cookies | ||
|
||
import ( | ||
"crypto/ecdh" | ||
"crypto/rand" | ||
"encoding/base64" | ||
) | ||
|
||
type PushKeysPublic struct { | ||
P256dh string `json:"p256dh"` | ||
Auth string `json:"auth"` | ||
} | ||
|
||
type PushKeys struct { | ||
Public PushKeysPublic | ||
Private string | ||
} | ||
|
||
func generatePushKeys() (*PushKeys, error) { | ||
curve := ecdh.P256() | ||
privateKey, err := curve.GenerateKey(rand.Reader) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
publicKey := privateKey.Public().(*ecdh.PublicKey) | ||
encodedPublicKey := base64.URLEncoding.EncodeToString(publicKey.Bytes()) | ||
|
||
privateKeyBytes := privateKey.Bytes() | ||
encodedPrivateKey := base64.URLEncoding.EncodeToString(privateKeyBytes) | ||
|
||
auth := make([]byte, 16) | ||
_, err = rand.Read(auth) | ||
if err != nil { | ||
return nil, err | ||
} | ||
encodedAuth := base64.URLEncoding.EncodeToString(auth) | ||
|
||
pushKeys := &PushKeys{ | ||
Public: PushKeysPublic{ | ||
P256dh: encodedPublicKey, | ||
Auth: encodedAuth, | ||
}, | ||
Private: encodedPrivateKey, | ||
} | ||
return pushKeys, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters