diff --git a/ergo-core/README.md b/ergo-core/README.md index b07bce00ef..f86714cbad 100644 --- a/ergo-core/README.md +++ b/ergo-core/README.md @@ -72,7 +72,9 @@ val handshakeMessageSerialized = HandshakeSerializer.toBytes(handshakeMessage) Serialize the message and send it. If the message arrived successfully, start communicating with the peer node. -All communication is wrapped with Message headers, format described [here](https://docs.ergoplatform.com/dev/p2p/network/#message-format). +All communication is wrapped with message headers. +Format described [here](https://docs.ergoplatform.com/dev/p2p/network/#message-format). +[MessageBase](src/main/scala/org/ergoplatform/network/message/MessageBase.scala) interface to implement. ## Syncing with the node diff --git a/ergo-core/src/main/scala/org/ergoplatform/network/message/MessageBase.scala b/ergo-core/src/main/scala/org/ergoplatform/network/message/MessageBase.scala new file mode 100644 index 0000000000..d348cbfb63 --- /dev/null +++ b/ergo-core/src/main/scala/org/ergoplatform/network/message/MessageBase.scala @@ -0,0 +1,48 @@ +package org.ergoplatform.network.message + +import org.ergoplatform.network.message.MessageConstants._ + +import scala.util.{Success, Try} + +/** + * Trait for a ergo network message + * + * @param spec - message specification + * @param input - message being wrapped, whether in byte-array form (if from outside), + * or structured data (if formed locally) + * @tparam Content - message data type + */ +trait MessageBase[Content] { + val spec: MessageSpec[Content] + val input: Either[Array[Byte], Content] + + /** + * Message data bytes + */ + lazy val dataBytes: Array[Byte] = input match { + case Left(db) => db + case Right(d) => spec.toBytes(d) + } + + /** + * Structured message content + */ + lazy val data: Try[Content] = input match { + case Left(db) => spec.parseBytesTry(db) + case Right(d) => Success(d) + } + + lazy val dataLength: Int = dataBytes.length + + /** + * @return serialized message length in bytes + */ + def messageLength: Int = { + if (dataLength > 0) { + HeaderLength + ChecksumLength + dataLength + } else { + HeaderLength + } + } + +} diff --git a/ergo-wallet/src/main/scala/org/ergoplatform/wallet/crypto/AES.scala b/ergo-wallet/src/main/scala/org/ergoplatform/wallet/crypto/AES.scala index 45a448c105..ffe68c7ab9 100644 --- a/ergo-wallet/src/main/scala/org/ergoplatform/wallet/crypto/AES.scala +++ b/ergo-wallet/src/main/scala/org/ergoplatform/wallet/crypto/AES.scala @@ -3,8 +3,8 @@ package org.ergoplatform.wallet.crypto import org.ergoplatform.sdk.wallet.settings.EncryptionSettings import javax.crypto.spec.{GCMParameterSpec, PBEKeySpec, SecretKeySpec} -import javax.crypto.{Cipher, SecretKeyFactory} -import scala.util.Try +import javax.crypto.{AEADBadTagException, Cipher, SecretKeyFactory} +import scala.util.{Failure, Try} object AES { @@ -51,7 +51,10 @@ object AES { val cipher = Cipher.getInstance(CipherAlgoInstance) cipher.init(Cipher.DECRYPT_MODE, keySpec, paramsSpec) - Try(cipher.doFinal(authTag ++ ciphertext)) + Try(cipher.doFinal(authTag ++ ciphertext)).recoverWith ({ + case _: AEADBadTagException => Failure(new Throwable("Bad wallet password")) + case e: Throwable => Failure(e) + }) } private def deriveEncryptionKeySpec(pass: Array[Char], salt: Array[Byte]) diff --git a/ergo-wallet/src/main/scala/org/ergoplatform/wallet/secrets/JsonSecretStorage.scala b/ergo-wallet/src/main/scala/org/ergoplatform/wallet/secrets/JsonSecretStorage.scala index e75c9b951c..173d4a69e8 100644 --- a/ergo-wallet/src/main/scala/org/ergoplatform/wallet/secrets/JsonSecretStorage.scala +++ b/ergo-wallet/src/main/scala/org/ergoplatform/wallet/secrets/JsonSecretStorage.scala @@ -73,7 +73,7 @@ final class JsonSecretStorage(val secretFile: File, encryptionSettings: Encrypti } } } - . fold(Failure(_), Success(_)) + .fold(Failure(_), Success(_)) .flatten } diff --git a/src/main/resources/panel/asset-manifest.json b/src/main/resources/panel/asset-manifest.json index e7f1cfb890..0053e186a5 100644 --- a/src/main/resources/panel/asset-manifest.json +++ b/src/main/resources/panel/asset-manifest.json @@ -1,18 +1,18 @@ { "files": { - "main.css": "/static/css/main.82878fab.chunk.css", - "main.js": "/static/js/main.53607d9d.chunk.js", - "main.js.map": "/static/js/main.53607d9d.chunk.js.map", - "runtime-main.js": "/static/js/runtime-main.219240e0.js", - "runtime-main.js.map": "/static/js/runtime-main.219240e0.js.map", - "static/css/2.9338f6a1.chunk.css": "/static/css/2.9338f6a1.chunk.css", - "static/js/2.6c0e10bc.chunk.js": "/static/js/2.6c0e10bc.chunk.js", - "static/js/2.6c0e10bc.chunk.js.map": "/static/js/2.6c0e10bc.chunk.js.map", + "main.css": "/static/css/main.95603572.chunk.css", + "main.js": "/static/js/main.4a62f34b.chunk.js", + "main.js.map": "/static/js/main.4a62f34b.chunk.js.map", + "runtime-main.js": "/static/js/runtime-main.3929add9.js", + "runtime-main.js.map": "/static/js/runtime-main.3929add9.js.map", + "static/css/2.8e5c4313.chunk.css": "/static/css/2.8e5c4313.chunk.css", + "static/js/2.82289ad5.chunk.js": "/static/js/2.82289ad5.chunk.js", + "static/js/2.82289ad5.chunk.js.map": "/static/js/2.82289ad5.chunk.js.map", "index.html": "/index.html", - "precache-manifest.29a69d72b7fe06699929c489c49d7886.js": "/precache-manifest.29a69d72b7fe06699929c489c49d7886.js", + "precache-manifest.5ec1b24f55df1ee3e942e6e6777944c3.js": "/precache-manifest.5ec1b24f55df1ee3e942e6e6777944c3.js", "service-worker.js": "/service-worker.js", - "static/css/2.9338f6a1.chunk.css.map": "/static/css/2.9338f6a1.chunk.css.map", - "static/css/main.82878fab.chunk.css.map": "/static/css/main.82878fab.chunk.css.map", + "static/css/2.8e5c4313.chunk.css.map": "/static/css/2.8e5c4313.chunk.css.map", + "static/css/main.95603572.chunk.css.map": "/static/css/main.95603572.chunk.css.map", "static/media/index.scss": "/static/media/Roboto-Thin.89e2666c.ttf", "static/media/close.feae5a5c.svg": "/static/media/close.feae5a5c.svg", "static/media/copy.icon.835ebda7.svg": "/static/media/copy.icon.835ebda7.svg", @@ -21,10 +21,10 @@ "static/media/remove.94c0849a.svg": "/static/media/remove.94c0849a.svg" }, "entrypoints": [ - "static/js/runtime-main.219240e0.js", - "static/css/2.9338f6a1.chunk.css", - "static/js/2.6c0e10bc.chunk.js", - "static/css/main.82878fab.chunk.css", - "static/js/main.53607d9d.chunk.js" + "static/js/runtime-main.3929add9.js", + "static/css/2.8e5c4313.chunk.css", + "static/js/2.82289ad5.chunk.js", + "static/css/main.95603572.chunk.css", + "static/js/main.4a62f34b.chunk.js" ] } \ No newline at end of file diff --git a/src/main/resources/panel/index.html b/src/main/resources/panel/index.html index 800144640e..6e3040d1a9 100644 --- a/src/main/resources/panel/index.html +++ b/src/main/resources/panel/index.html @@ -1 +1 @@ -
`s get reset. However, we also reset the\n// bottom margin to use `rem` units instead of `em`.\np {\n margin-top: 0;\n margin-bottom: $paragraph-margin-bottom;\n}\n\n// Abbreviations\n//\n// 1. Duplicate behavior to the data-* attribute for our tooltip plugin\n// 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.\n// 3. Add explicit cursor to indicate changed behavior.\n// 4. Remove the bottom border in Firefox 39-.\n// 5. Prevent the text-decoration to be skipped.\n\nabbr[title],\nabbr[data-original-title] { // 1\n text-decoration: underline; // 2\n text-decoration: underline dotted; // 2\n cursor: help; // 3\n border-bottom: 0; // 4\n text-decoration-skip-ink: none; // 5\n}\n\naddress {\n margin-bottom: 1rem;\n font-style: normal;\n line-height: inherit;\n}\n\nol,\nul,\ndl {\n margin-top: 0;\n margin-bottom: 1rem;\n}\n\nol ol,\nul ul,\nol ul,\nul ol {\n margin-bottom: 0;\n}\n\ndt {\n font-weight: $dt-font-weight;\n}\n\ndd {\n margin-bottom: .5rem;\n margin-left: 0; // Undo browser default\n}\n\nblockquote {\n margin: 0 0 1rem;\n}\n\nb,\nstrong {\n font-weight: $font-weight-bolder; // Add the correct font weight in Chrome, Edge, and Safari\n}\n\nsmall {\n @include font-size(80%); // Add the correct font size in all browsers\n}\n\n//\n// Prevent `sub` and `sup` elements from affecting the line height in\n// all browsers.\n//\n\nsub,\nsup {\n position: relative;\n @include font-size(75%);\n line-height: 0;\n vertical-align: baseline;\n}\n\nsub { bottom: -.25em; }\nsup { top: -.5em; }\n\n\n//\n// Links\n//\n\na {\n color: $link-color;\n text-decoration: $link-decoration;\n background-color: transparent; // Remove the gray background on active links in IE 10.\n\n @include hover() {\n color: $link-hover-color;\n text-decoration: $link-hover-decoration;\n }\n}\n\n// And undo these styles for placeholder links/named anchors (without href).\n// It would be more straightforward to just use a[href] in previous block, but that\n// causes specificity issues in many other styles that are too complex to fix.\n// See https://github.com/twbs/bootstrap/issues/19402\n\na:not([href]):not([class]) {\n color: inherit;\n text-decoration: none;\n\n @include hover() {\n color: inherit;\n text-decoration: none;\n }\n}\n\n\n//\n// Code\n//\n\npre,\ncode,\nkbd,\nsamp {\n font-family: $font-family-monospace;\n @include font-size(1em); // Correct the odd `em` font sizing in all browsers.\n}\n\npre {\n // Remove browser default top margin\n margin-top: 0;\n // Reset browser default of `1em` to use `rem`s\n margin-bottom: 1rem;\n // Don't allow content to break outside\n overflow: auto;\n // Disable auto-hiding scrollbar in IE & legacy Edge to avoid overlap,\n // making it impossible to interact with the content\n -ms-overflow-style: scrollbar;\n}\n\n\n//\n// Figures\n//\n\nfigure {\n // Apply a consistent margin strategy (matches our type styles).\n margin: 0 0 1rem;\n}\n\n\n//\n// Images and content\n//\n\nimg {\n vertical-align: middle;\n border-style: none; // Remove the border on images inside links in IE 10-.\n}\n\nsvg {\n // Workaround for the SVG overflow bug in IE10/11 is still required.\n // See https://github.com/twbs/bootstrap/issues/26878\n overflow: hidden;\n vertical-align: middle;\n}\n\n\n//\n// Tables\n//\n\ntable {\n border-collapse: collapse; // Prevent double borders\n}\n\ncaption {\n padding-top: $table-cell-padding;\n padding-bottom: $table-cell-padding;\n color: $table-caption-color;\n text-align: left;\n caption-side: bottom;\n}\n\nth {\n // Matches default `