Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 2.2.2
version = 2.7.5
style = defaultWithAlign
maxColumn = 160
align.openParenCallSite = false
Expand Down
26 changes: 13 additions & 13 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ libraryDependencies ++= {
val akkaHttpV = "10.2.1"

Seq(
"com.pauldijou" %% "jwt-core" % "4.3.0",
"org.apache.httpcomponents" % "fluent-hc" % "4.5.13",
"org.bouncycastle" % "bcprov-jdk15on" % "1.67",
"com.typesafe.akka" %% "akka-actor" % akkaV,
"com.typesafe.akka" %% "akka-stream" % akkaV,
"com.typesafe.akka" %% "akka-stream-testkit" % akkaV % Test,
"com.typesafe.akka" %% "akka-http" % akkaHttpV,
"com.typesafe.akka" %% "akka-http-testkit" % akkaHttpV % Test,
"org.scalatest" %% "scalatest" % "3.3.0-SNAP2" % Test,
"com.github.tomakehurst" % "wiremock" % "2.27.2" % Test,
"com.pauldijou" %% "jwt-core" % "4.3.0",
"org.apache.httpcomponents" % "fluent-hc" % "4.5.13",
"org.bouncycastle" % "bcprov-jdk15on" % "1.67",
"com.typesafe.akka" %% "akka-actor" % akkaV,
"com.typesafe.akka" %% "akka-stream" % akkaV,
"com.typesafe.akka" %% "akka-stream-testkit" % akkaV % Test,
"com.typesafe.akka" %% "akka-http" % akkaHttpV,
"com.typesafe.akka" %% "akka-http-testkit" % akkaHttpV % Test,
"org.scalatest" %% "scalatest" % "3.3.0-SNAP2" % Test,
"com.github.tomakehurst" % "wiremock" % "2.27.2" % Test,
)
}

Expand Down Expand Up @@ -45,10 +45,10 @@ publishTo in ThisBuild := {
scmInfo := Some(
ScmInfo(
url("https://github.com/TeamWanari/web-push"),
"scm:git:git@github.com:TeamWanari/web-push.git"
)
"scm:git:git@github.com:TeamWanari/web-push.git",
),
)

developers := List(
Developer("Csabi", "Csaba Pálfi", "csibcsab@wanari.com", url("https://www.wanari.com"))
Developer("Csabi", "Csaba Pálfi", "csibcsab@wanari.com", url("https://www.wanari.com")),
)
3 changes: 1 addition & 2 deletions src/main/scala/com/wanari/webpush/Encryption.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import java.security.{KeyPairGenerator, PublicKey, SecureRandom}
import org.bouncycastle.jce.ECNamedCurveTable
import org.bouncycastle.jce.provider.BouncyCastleProvider

/**
* Encryption object to mange payload ECDH encryption.
/** Encryption object to mange payload ECDH encryption.
*/
object Encryption {
private val localCurve = KeyPairGenerator.getInstance("ECDH", BouncyCastleProvider.PROVIDER_NAME)
Expand Down
3 changes: 1 addition & 2 deletions src/main/scala/com/wanari/webpush/HttpEce.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import org.bouncycastle.crypto.generators.HKDFBytesGenerator
import org.bouncycastle.crypto.params.HKDFParameters
import org.bouncycastle.jce.provider.BouncyCastleProvider

/**
* A simplified implementation of HTTP ECE (Encrypted Content Encoding).
/** A simplified implementation of HTTP ECE (Encrypted Content Encoding).
*/
object HttpEce {
def encrypt(keys: KeyPair, buffer: Array[Byte], salt: Array[Byte], dh: PublicKey, authSecret: Array[Byte]): Array[Byte] = {
Expand Down
19 changes: 6 additions & 13 deletions src/main/scala/com/wanari/webpush/PushService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,21 @@ import pdi.jwt.JwtAlgorithm.ES256
import scala.concurrent.Future
import scala.concurrent.duration._

/**
* Push service.
/** Push service.
*/
case class PushService(publicKey: ECPublicKey, privateKey: ECPrivateKey, subject: String, exp: FiniteDuration = 12.hours)(implicit as: ActorSystem) {
protected def httpExt: HttpExt = Http()
private val base64encoder = Base64.getUrlEncoder
private val defaultTtl: Int = 2419200

/**
* Send a data free push notification.
/** Send a data free push notification.
*
* @param subscription Browser subscription object.
* @return HttpResponse from push server.
*/
def send(subscription: Subscription): Future[HttpResponse] = send(subscription, None, defaultTtl)

/**
* Send a data free push notification.
/** Send a data free push notification.
*
* @param subscription Browser subscription object.
* @param ttl Suggestion to the message server for how long it should keep the message
Expand All @@ -40,8 +37,7 @@ case class PushService(publicKey: ECPublicKey, privateKey: ECPrivateKey, subject
*/
def send(subscription: Subscription, ttl: Int): Future[HttpResponse] = send(subscription, None, ttl)

/**
* Sends a data bearing push notification.
/** Sends a data bearing push notification.
*
* @param subscription Browser subscription object.
* @param payload Push notification payload.
Expand All @@ -53,9 +49,7 @@ case class PushService(publicKey: ECPublicKey, privateKey: ECPrivateKey, subject

def send(subscription: Subscription, payload: String): Future[HttpResponse] = send(subscription, Some(payload.getBytes), defaultTtl)

/**
*
* Sends a data bearing push notification.
/** Sends a data bearing push notification.
*
* @param subscription Browser subscription object.
* @param payload Push notification data as a Byte Array.
Expand All @@ -65,8 +59,7 @@ case class PushService(publicKey: ECPublicKey, privateKey: ECPrivateKey, subject
*/
def send(subscription: Subscription, payload: Array[Byte], ttl: Int = defaultTtl): Future[HttpResponse] = send(subscription, Some(payload), ttl)

/**
* Returns the server public key as a URL safe base64 string.
/** Returns the server public key as a URL safe base64 string.
*/
def publicKeyToBase64: String = {
base64encoder.withoutPadding().encodeToString(Utils.publicKeyToBytes(publicKey.asInstanceOf[ECPublicKey]))
Expand Down