Skip to content

Commit

Permalink
Use signedBuild property in frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregor Billing committed Oct 1, 2020
1 parent 4e1ed13 commit ca5c761
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import org.worldcubeassociation.tnoodle.server.crypto.BuildVerification

@Serializable
data class VersionInfo(
val runningVersion: String,
val projectName: String,
val projectVersion: String,
val signedBuild: Boolean,
Expand All @@ -15,7 +14,6 @@ data class VersionInfo(
companion object {
fun fromEnvironmentConfig(config: ServerEnvironmentConfig): VersionInfo {
return VersionInfo(
config.title,
config.projectName,
config.projectVersion,
BuildVerification.BUILD_VERIFIED,
Expand Down
85 changes: 42 additions & 43 deletions tnoodle-ui/src/main/components/VersionInfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ const VersionInfo = connect(
currentTnoodle: null,
allowedTnoodleVersions: null,
runningVersion: null,
officialBuild: null,
signedBuild: null,
signatureKeyBytes: null,
wcaPublicKeyBytes: null,
wcaResponse: false,
tnoodleResponse: false,
};
Expand All @@ -31,46 +33,53 @@ const VersionInfo = connect(
if (!response) {
return;
}
let {current, allowed, publicKeyBytes} = response;
this.setState({
...this.state,
currentTnoodle: response.current,
allowedTnoodleVersions: response.allowed,
currentTnoodle: current,
allowedTnoodleVersions: allowed,
wcaPublicKeyBytes: publicKeyBytes,
wcaResponse: true,
});
this.analizeVersion();
this.analyzeVersion();
});

fetchRunningVersion().then((response) => {
if (!response) {
return;
}
let { projectName, projectVersion, signedBuild } = response;
let {projectName, projectVersion, signedBuild, signatureKeyBytes} = response;
this.setState({
...this.state,
// Running version is based on projectName and projectVersion
runningVersion:
projectVersion != null && projectVersion != null
projectName != null && projectVersion != null
? `${projectName}-${projectVersion}`
: "",
officialBuild: signedBuild,
signedBuild: signedBuild,
signatureKeyBytes: signatureKeyBytes,
tnoodleResponse: true,
});
this.analizeVersion();
this.analyzeVersion();
});
}

signatureValid() {
return this.state.signedBuild && this.state.signatureKeyBytes === this.state.wcaPublicKeyBytes;
}

// This method avoids global state update while rendering
analizeVersion() {
// We wait until both wca and tnoodle answes
analyzeVersion() {
// We wait until both wca and tnoodle answers
if (!this.state.tnoodleResponse || !this.state.wcaResponse) {
return;
}

let runningVersion = this.state.runningVersion;
let allowedVersions = this.state.allowedTnoodleVersions;
let officialBuild = this.state.officialBuild;
let signedBuild = this.signatureValid();

if (!officialBuild || !allowedVersions.includes(runningVersion)) {
if (!signedBuild || !allowedVersions.includes(runningVersion)) {
this.props.updateOfficialZipStatus(false);
}
}
Expand All @@ -79,54 +88,44 @@ const VersionInfo = connect(
let runningVersion = this.state.runningVersion;
let allowedVersions = this.state.allowedTnoodleVersions;
let currentTnoodle = this.state.currentTnoodle;
let officialBuild = this.state.officialBuild;
let signedBuild = this.signatureValid();

// We cannot analyze TNoodle version here. We do not bother the user.
if (!runningVersion || !allowedVersions) {
return null;
}

// Generated version is not an official jar
if (!officialBuild) {
return (
<div className="alert alert-danger m-0">
This TNoodle version is not official and scrambles
generated with this must not be used in competition. You
are on version {runningVersion}, you should use{" "}
{currentTnoodle.name} available{" "}
<a href={currentTnoodle.download}>here</a>
</div>
);
}

// Best case scenario. We place this after the officialBuild
// so we can avoid not official build from being accidentally used.
if (runningVersion === currentTnoodle.name) {
return null;
}
// Running version is not the most recent release
if (runningVersion !== currentTnoodle.name) {
// Running version is allowed, but not the latest.
if (allowedVersions.includes(runningVersion)) {
return (
<div className="alert alert-info m-0">
You are running {runningVersion}, which is still
allowed, but you should upgrade to {currentTnoodle.name}{" "}
available <a href={currentTnoodle.download}>here</a>.
</div>
);
}

// Running version is not allowed anymore.
if (!allowedVersions.includes(runningVersion)) {
return (
<div className="alert alert-danger m-0">
This TNoodle version is not allowed. Do not use
scrambles generated in any official competition and
consider downloading the latest version{" "}
<a href={this.state.currentTnoodle.download}>here</a>.
<a href={currentTnoodle.download}>here</a>.
</div>
);
}

// Running version is allowed, but not the latest.
if (
allowedVersions.includes(runningVersion) &&
runningVersion !== currentTnoodle.name
) {
// Generated version is not an officially signed jar
if (!signedBuild) {
return (
<div className="alert alert-info m-0">
You are running {runningVersion}, which is still
allowed, but you should upgrade to {currentTnoodle.name}{" "}
available <a href={currentTnoodle.download}>here</a>.
<div className="alert alert-danger m-0">
This TNoodle version is not signed. Do not use
scrambles generated in any official competition and
consider downloading the official program{" "}
<a href={currentTnoodle.download}>here</a>
</div>
);
}
Expand Down

0 comments on commit ca5c761

Please sign in to comment.