Skip to content

Commit e9d1b8d

Browse files
committed
signal-server
1 parent c5684ad commit e9d1b8d

870 files changed

Lines changed: 127993 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

jdk_17_maven/cs/rest/signal-server/LICENSE

Lines changed: 661 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Signal-Server
2+
=================
3+
4+
Documentation
5+
-------------
6+
7+
Looking for protocol documentation? Check out the website!
8+
9+
https://signal.org/docs/
10+
11+
Cryptography Notice
12+
------------
13+
14+
This distribution includes cryptographic software. The country in which you currently reside may have restrictions on the import, possession, use, and/or re-export to another country, of encryption software.
15+
BEFORE using any encryption software, please check your country's laws, regulations and policies concerning the import, possession, or use, and re-export of encryption software, to see if this is permitted.
16+
See <https://www.wassenaar.org/> for more information.
17+
18+
The U.S. Government Department of Commerce, Bureau of Industry and Security (BIS), has classified this software as Export Commodity Control Number (ECCN) 5D002.C.1, which includes information security software using or performing cryptographic functions with asymmetric algorithms.
19+
The form and manner of this distribution makes it eligible for export under the License Exception ENC Technology Software Unrestricted (TSU) exception (see the BIS Export Administration Regulations, Section 740.13) for both object code and source code.
20+
21+
License
22+
---------------------
23+
24+
Copyright 2013-2023 Signal Messenger, LLC
25+
26+
Licensed under the AGPLv3: https://www.gnu.org/licenses/agpl-3.0.html
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>TextSecureServer</artifactId>
7+
<groupId>org.whispersystems.textsecure</groupId>
8+
<version>JGITVER</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
<artifactId>api-doc</artifactId>
12+
13+
<dependencies>
14+
<dependency>
15+
<groupId>org.whispersystems.textsecure</groupId>
16+
<artifactId>service</artifactId>
17+
<version>${project.version}</version>
18+
</dependency>
19+
</dependencies>
20+
21+
<build>
22+
<plugins>
23+
<plugin>
24+
<groupId>io.swagger.core.v3</groupId>
25+
<artifactId>swagger-maven-plugin</artifactId>
26+
<version>2.2.8</version>
27+
<configuration>
28+
<outputFileName>signal-server-openapi</outputFileName>
29+
<outputPath>${project.build.directory}/openapi</outputPath>
30+
<outputFormat>YAML</outputFormat>
31+
<configurationFilePath>${project.basedir}/src/main/resources/openapi/openapi-configuration.yaml
32+
</configurationFilePath>
33+
</configuration>
34+
<executions>
35+
<execution>
36+
<phase>compile</phase>
37+
<goals>
38+
<goal>resolve</goal>
39+
</goals>
40+
</execution>
41+
</executions>
42+
</plugin>
43+
<plugin>
44+
<groupId>com.google.cloud.tools</groupId>
45+
<artifactId>jib-maven-plugin</artifactId>
46+
<configuration>
47+
<!-- we don't want jib to execute on this module -->
48+
<skip>true</skip>
49+
</configuration>
50+
</plugin>
51+
</plugins>
52+
</build>
53+
</project>
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Copyright 2023 Signal Messenger, LLC
3+
* SPDX-License-Identifier: AGPL-3.0-only
4+
*/
5+
6+
package org.signal.openapi;
7+
8+
import com.fasterxml.jackson.annotation.JsonView;
9+
import com.fasterxml.jackson.databind.JavaType;
10+
import com.fasterxml.jackson.databind.type.SimpleType;
11+
import io.dropwizard.auth.Auth;
12+
import io.swagger.v3.jaxrs2.ResolvedParameter;
13+
import io.swagger.v3.jaxrs2.ext.AbstractOpenAPIExtension;
14+
import io.swagger.v3.jaxrs2.ext.OpenAPIExtension;
15+
import io.swagger.v3.oas.models.Components;
16+
import java.lang.annotation.Annotation;
17+
import java.lang.reflect.Type;
18+
import java.util.Iterator;
19+
import java.util.List;
20+
import java.util.Optional;
21+
import java.util.ServiceLoader;
22+
import java.util.Set;
23+
import javax.ws.rs.Consumes;
24+
import org.whispersystems.textsecuregcm.auth.AuthenticatedAccount;
25+
import org.whispersystems.textsecuregcm.auth.DisabledPermittedAuthenticatedAccount;
26+
27+
/**
28+
* One of the extension mechanisms of Swagger Core library (OpenAPI processor) is via custom implementations
29+
* of the {@link AbstractOpenAPIExtension} class.
30+
* <p/>
31+
* The purpose of this extension is to customize certain aspects of the OpenAPI model generation on a lower level.
32+
* This extension works in coordination with {@link OpenApiReader} that has access to the model on a higher level.
33+
* <p/>
34+
* The extension is enabled by being listed in {@code META-INF/services/io.swagger.v3.jaxrs2.ext.OpenAPIExtension} file.
35+
* @see ServiceLoader
36+
* @see OpenApiReader
37+
* @see <a href="https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Extensions">Swagger 2.X Extensions</a>
38+
*/
39+
public class OpenApiExtension extends AbstractOpenAPIExtension {
40+
41+
public static final ResolvedParameter AUTHENTICATED_ACCOUNT = new ResolvedParameter();
42+
43+
public static final ResolvedParameter OPTIONAL_AUTHENTICATED_ACCOUNT = new ResolvedParameter();
44+
45+
public static final ResolvedParameter DISABLED_PERMITTED_AUTHENTICATED_ACCOUNT = new ResolvedParameter();
46+
47+
public static final ResolvedParameter OPTIONAL_DISABLED_PERMITTED_AUTHENTICATED_ACCOUNT = new ResolvedParameter();
48+
49+
/**
50+
* When parsing endpoint methods, Swagger will treat the first parameter not annotated as header/path/query param
51+
* as a request body (and will ignore other not annotated parameters). In our case, this behavior conflicts with
52+
* the {@code @Auth}-annotated parameters. Here we're checking if parameters are known to be anything other than
53+
* a body and return an appropriate {@link ResolvedParameter} representation.
54+
*/
55+
@Override
56+
public ResolvedParameter extractParameters(
57+
final List<Annotation> annotations,
58+
final Type type,
59+
final Set<Type> typesToSkip,
60+
final Components components,
61+
final Consumes classConsumes,
62+
final Consumes methodConsumes,
63+
final boolean includeRequestBody,
64+
final JsonView jsonViewAnnotation,
65+
final Iterator<OpenAPIExtension> chain) {
66+
67+
if (annotations.stream().anyMatch(a -> a.annotationType().equals(Auth.class))) {
68+
// this is the case of authenticated endpoint,
69+
if (type instanceof SimpleType simpleType
70+
&& simpleType.getRawClass().equals(AuthenticatedAccount.class)) {
71+
return AUTHENTICATED_ACCOUNT;
72+
}
73+
if (type instanceof SimpleType simpleType
74+
&& simpleType.getRawClass().equals(DisabledPermittedAuthenticatedAccount.class)) {
75+
return DISABLED_PERMITTED_AUTHENTICATED_ACCOUNT;
76+
}
77+
if (type instanceof SimpleType simpleType
78+
&& isOptionalOfType(simpleType, AuthenticatedAccount.class)) {
79+
return OPTIONAL_AUTHENTICATED_ACCOUNT;
80+
}
81+
if (type instanceof SimpleType simpleType
82+
&& isOptionalOfType(simpleType, DisabledPermittedAuthenticatedAccount.class)) {
83+
return OPTIONAL_DISABLED_PERMITTED_AUTHENTICATED_ACCOUNT;
84+
}
85+
}
86+
87+
return super.extractParameters(
88+
annotations,
89+
type,
90+
typesToSkip,
91+
components,
92+
classConsumes,
93+
methodConsumes,
94+
includeRequestBody,
95+
jsonViewAnnotation,
96+
chain);
97+
}
98+
99+
private static boolean isOptionalOfType(final SimpleType simpleType, final Class<?> expectedType) {
100+
if (!simpleType.getRawClass().equals(Optional.class)) {
101+
return false;
102+
}
103+
final List<JavaType> typeParameters = simpleType.getBindings().getTypeParameters();
104+
if (typeParameters.isEmpty()) {
105+
return false;
106+
}
107+
return typeParameters.get(0) instanceof SimpleType optionalParameterType
108+
&& optionalParameterType.getRawClass().equals(expectedType);
109+
}
110+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright 2023 Signal Messenger, LLC
3+
* SPDX-License-Identifier: AGPL-3.0-only
4+
*/
5+
6+
package org.signal.openapi;
7+
8+
import static com.google.common.base.MoreObjects.firstNonNull;
9+
import static org.signal.openapi.OpenApiExtension.AUTHENTICATED_ACCOUNT;
10+
import static org.signal.openapi.OpenApiExtension.DISABLED_PERMITTED_AUTHENTICATED_ACCOUNT;
11+
import static org.signal.openapi.OpenApiExtension.OPTIONAL_AUTHENTICATED_ACCOUNT;
12+
import static org.signal.openapi.OpenApiExtension.OPTIONAL_DISABLED_PERMITTED_AUTHENTICATED_ACCOUNT;
13+
14+
import com.fasterxml.jackson.annotation.JsonView;
15+
import com.google.common.collect.ImmutableList;
16+
import io.swagger.v3.jaxrs2.Reader;
17+
import io.swagger.v3.jaxrs2.ResolvedParameter;
18+
import io.swagger.v3.oas.models.Operation;
19+
import io.swagger.v3.oas.models.security.SecurityRequirement;
20+
import java.lang.annotation.Annotation;
21+
import java.lang.reflect.Type;
22+
import java.util.Collections;
23+
import java.util.List;
24+
import javax.ws.rs.Consumes;
25+
26+
/**
27+
* One of the extension mechanisms of Swagger Core library (OpenAPI processor) is via custom implementations
28+
* of the {@link Reader} class.
29+
* <p/>
30+
* The purpose of this extension is to customize certain aspects of the OpenAPI model generation on a higher level.
31+
* This extension works in coordination with {@link OpenApiExtension} that has access to the model on a lower level.
32+
* <p/>
33+
* The extension is enabled by being listed in {@code resources/openapi/openapi-configuration.yaml} file.
34+
* @see OpenApiExtension
35+
* @see <a href="https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Extensions">Swagger 2.X Extensions</a>
36+
*/
37+
public class OpenApiReader extends Reader {
38+
39+
private static final String AUTHENTICATED_ACCOUNT_AUTH_SCHEMA = "authenticatedAccount";
40+
41+
42+
/**
43+
* Overriding this method allows converting a resolved parameter into other operation entities,
44+
* in this case, into security requirements.
45+
*/
46+
@Override
47+
protected ResolvedParameter getParameters(
48+
final Type type,
49+
final List<Annotation> annotations,
50+
final Operation operation,
51+
final Consumes classConsumes,
52+
final Consumes methodConsumes,
53+
final JsonView jsonViewAnnotation) {
54+
final ResolvedParameter resolved = super.getParameters(
55+
type, annotations, operation, classConsumes, methodConsumes, jsonViewAnnotation);
56+
57+
if (resolved == AUTHENTICATED_ACCOUNT || resolved == DISABLED_PERMITTED_AUTHENTICATED_ACCOUNT) {
58+
operation.setSecurity(ImmutableList.<SecurityRequirement>builder()
59+
.addAll(firstNonNull(operation.getSecurity(), Collections.emptyList()))
60+
.add(new SecurityRequirement().addList(AUTHENTICATED_ACCOUNT_AUTH_SCHEMA))
61+
.build());
62+
}
63+
if (resolved == OPTIONAL_AUTHENTICATED_ACCOUNT || resolved == OPTIONAL_DISABLED_PERMITTED_AUTHENTICATED_ACCOUNT) {
64+
operation.setSecurity(ImmutableList.<SecurityRequirement>builder()
65+
.addAll(firstNonNull(operation.getSecurity(), Collections.emptyList()))
66+
.add(new SecurityRequirement().addList(AUTHENTICATED_ACCOUNT_AUTH_SCHEMA))
67+
.add(new SecurityRequirement())
68+
.build());
69+
}
70+
71+
return resolved;
72+
}
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.signal.openapi.OpenApiExtension
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
resourcePackages:
2+
- org.whispersystems.textsecuregcm
3+
prettyPrint: true
4+
cacheTTL: 0
5+
readerClass: org.signal.openapi.OpenApiReader
6+
openAPI:
7+
info:
8+
title: Signal Server API
9+
license:
10+
name: AGPL-3.0-only
11+
url: https://www.gnu.org/licenses/agpl-3.0.txt
12+
servers:
13+
- url: https://chat.signal.org
14+
description: Production service
15+
- url: https://chat.staging.signal.org
16+
description: Staging service
17+
components:
18+
securitySchemes:
19+
authenticatedAccount:
20+
type: http
21+
scheme: basic
22+
description: |
23+
Account authentication is based on Basic authentication schema,
24+
where `username` has a format of `<user_id>[.<device_id>]`. If `device_id` is not specified,
25+
user's `main` device is assumed.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2022 Signal Messenger, LLC
4+
~ SPDX-License-Identifier: AGPL-3.0-only
5+
-->
6+
7+
<project xmlns="http://maven.apache.org/POM/4.0.0"
8+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
10+
<parent>
11+
<artifactId>TextSecureServer</artifactId>
12+
<groupId>org.whispersystems.textsecure</groupId>
13+
<version>JGITVER</version>
14+
</parent>
15+
16+
<modelVersion>4.0.0</modelVersion>
17+
<artifactId>event-logger</artifactId>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>com.google.cloud</groupId>
22+
<artifactId>google-cloud-logging</artifactId>
23+
</dependency>
24+
<dependency>
25+
<groupId>org.jetbrains.kotlin</groupId>
26+
<artifactId>kotlin-stdlib</artifactId>
27+
<exclusions>
28+
<exclusion>
29+
<groupId>org.jetbrains</groupId>
30+
<!--
31+
depends on an outdated version (13.0) for JDK 6 compatibility, but it’s safe to override
32+
https://youtrack.jetbrains.com/issue/KT-25047
33+
-->
34+
<artifactId>annotations</artifactId>
35+
</exclusion>
36+
</exclusions>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.jetbrains.kotlinx</groupId>
40+
<artifactId>kotlinx-serialization-json</artifactId>
41+
<version>${kotlinx-serialization.version}</version>
42+
</dependency>
43+
</dependencies>
44+
45+
<build>
46+
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
47+
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
48+
49+
<plugins>
50+
<plugin>
51+
<groupId>org.jetbrains.kotlin</groupId>
52+
<artifactId>kotlin-maven-plugin</artifactId>
53+
<version>${kotlin.version}</version>
54+
55+
<executions>
56+
<execution>
57+
<id>compile</id>
58+
<goals>
59+
<goal>compile</goal>
60+
</goals>
61+
</execution>
62+
63+
<execution>
64+
<id>test-compile</id>
65+
<goals>
66+
<goal>test-compile</goal>
67+
</goals>
68+
</execution>
69+
</executions>
70+
<configuration>
71+
<compilerPlugins>
72+
<plugin>kotlinx-serialization</plugin>
73+
</compilerPlugins>
74+
</configuration>
75+
<dependencies>
76+
<dependency>
77+
<groupId>org.jetbrains.kotlin</groupId>
78+
<artifactId>kotlin-maven-serialization</artifactId>
79+
<version>${kotlin.version}</version>
80+
</dependency>
81+
</dependencies>
82+
</plugin>
83+
<plugin>
84+
<groupId>com.google.cloud.tools</groupId>
85+
<artifactId>jib-maven-plugin</artifactId>
86+
<configuration>
87+
<!-- we don't want jib to execute on this module -->
88+
<skip>true</skip>
89+
</configuration>
90+
</plugin>
91+
</plugins>
92+
</build>
93+
94+
</project>

0 commit comments

Comments
 (0)