Skip to content

Commit b3b5226

Browse files
committed
Added mutexes and synchronic capacities
0 parents  commit b3b5226

File tree

430 files changed

+13570
-0
lines changed

Some content is hidden

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

430 files changed

+13570
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Esteban
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# TFProtocol (Transfer Protocol)
2+
3+
The TFProtocol works by sending text commands from client to the
4+
server in a TCP connection. Every time a command is received at the
5+
server it responds with a command execution status. TFProtocol has
6+
evolved from its origin to become a modular meta-protocol that allows
7+
the addition of any type of module to gain functionalities. Those
8+
functionalietes goes from the main core -that allows text commands
9+
execution- to complex modules that give you the posiblity to implement
10+
chat applications or even execute any thrid-party modules at the
11+
server side written in any language. Example of those modules are the
12+
support added to run the main databases services like PostgreSQL or
13+
MySQL.
14+
15+
With TFProtocol you can develop Android Apps that can be integrated
16+
through network communication with other apps or services like web
17+
sites or IoT devices. The frontiers of what you may do with TFProtocol
18+
and in particular with its ACE Subsystem it is only limited by your
19+
imagination.
20+
21+
Services you can rent from us:
22+
23+
-Space in a shared VPS with TFProtocol and other services on demand,
24+
this way you can develop applications that interact among them.
25+
-Subdomains, this way you can use a domain name for your developments
26+
instead of an ip address.
27+
-Shared o dedicated VPN service on a VPS with a powerfull console
28+
administration that allows you to create easly any number of profiles.
29+
-Technical Support and assistance.
30+
31+
If you require any of our services you can contact us at:
32+
* lmdelbahia@gmail.com
33+
* n4b3ts3@gmail.com
34+
## Sandbox How-To-Use
35+
For testing the capacities of this protocol you can try our sandbox (it is free), is located in an isolate space with low capacities giving you a lot of features explained in the documents above, you may notice that those documents explains which data are transfer with each command you execute... When you are instancing any tfprotocol class you may give the next data to connect to sandbox (For production you must read the production section).</br>
36+
* IP/Domain Name: tfproto.expresscuba.com
37+
* TCP Port: 10999
38+
* Public Key:
39+
-----BEGIN PUBLIC KEY-----
40+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlhjLEFcJQBkXlyP46utJ
41+
JTrcE2v8KFXVwjAjJ5aiHuNmUBzo9pYLSLqr4ZDbmsmrEBlyZvL2O7wYqjqw3UnR
42+
dQCxhxfWeNSV3uXKEDDJQdkpbUpSvmNFXL0JZHDX1HHQ/LNPzEj+bv2jFyq2H+ic
43+
WNjv0LWeI5iIpip2H3U55POiog822CRglNjcARWfbh0mWlAs3hHIbac9Ar2DK3gn
44+
uqRPPIYMbUYcify/gJrm50Gls1v+zaH+mcMB7VqSvDzskOm34NoL2KNtjZTZnM6k
45+
x0j5+s8dfqPXcgmO/YyOr002ijLUPE/PPV5zsIyObze/Z/ONGtO5Bd9ZhnpZCEEO
46+
zQIDAQAB
47+
-----END PUBLIC KEY-----
48+
* Hash: testhash
49+
* Version: 0.0
50+
* Length: 36
51+
52+
Extended Arbitrary Code Execution or ACE allows only to execute the next binaries inside the sandbox (in production you can execute any binary you want, so you are able to run any web backend like Django, .NET CORE, etc...) The <b >inskey</b> for access to ACE it is <b>tfproto</b>
53+
<br>
54+
* /bin/ls
55+
* /bin/echo
56+
57+
Parameters for /bin/ls must be: /bin/ls /
58+
59+
Parameters for /bin/echo can be anyone
60+
61+
## Production
62+
For use tfprotocol for a production environment you have to contact directly with us at:
63+
* lmdelbahia@gmail.com
64+
* n4b3ts3@gmail.com

auth/src/com/nerox/Auth/Auth.java

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
package com.nerox.Auth;
2+
import com.nerox.Auth.Errors.TFAuthErrors;
3+
import com.nerox.Auth.Models.Model;
4+
import com.nerox.client.Tfprotocol;
5+
import com.nerox.client.TfprotocolWrapper;
6+
import com.nerox.client.misc.StatusServer;
7+
import com.nerox.client.modules.ExtendedSub1;
8+
9+
/**
10+
* How should this work...
11+
* 1- You instantiate this class.
12+
* 1.1- (AUTO) The connection is established.
13+
* 1.2- (CONDITION) If the connection is not established or previously established and passed to
14+
* the constructor, the class with end.
15+
* 2- There is available three options:
16+
* 2.1- Login
17+
* 2.1.1- You must create a model, instancing the class TFLogin.LoginModel.
18+
* 2.1.2- You must pass the created model to the Login function.
19+
* 2.1.3- Wait for the response.
20+
* 2.2- Register
21+
* 2.2.1- You must create a model, instancing the class TFRegister.RegisterModel.
22+
* 2.2.2- You must pass the created model to the Register function.
23+
* 2.1.3- Wait for the response.
24+
* 2.3- Logout
25+
* 2.3.1- Call this function and Wait for the response.
26+
* */
27+
public final class Auth {
28+
// Enums
29+
protected enum States {
30+
Idle,
31+
Login,
32+
Register,
33+
Handling_in,
34+
Handling_out
35+
}
36+
// Statics Variables
37+
public static States currentState = States.Idle;
38+
39+
// Variables de instancia
40+
private String IP;
41+
private int PORT;
42+
private int LEN ;
43+
private String PROTO;
44+
private String PUK;
45+
private String HASH;
46+
47+
// Constants
48+
private static final String PATH = "secure.sd";
49+
50+
// Other classes references
51+
private ExtendedSub1 extended;
52+
static TFCrypto crypto;
53+
54+
// Class Results
55+
Model user;
56+
57+
// Constructors
58+
/**
59+
* This constructor receives a connection already stablished.
60+
* and use it for Authentication functions...
61+
* @param tf Connection previously created
62+
* */
63+
public Auth(ExtendedSub1 tf, Tfprotocol tfprotocol)throws TFAuthErrors
64+
{
65+
assert tf.isConnect() && tf.getConHandler().equals(tfprotocol.getConHandler());
66+
this.extended = tf;
67+
init();
68+
}
69+
70+
/**
71+
* This constructor create an instance of tfprotocol
72+
* @param ip The Internet Protocol Address for connect to the server...
73+
* @param port The open port of tfprotocol service on server...
74+
* @param proto The protocol version, for example: 0.0, 1.0 etc
75+
* @param len UPDATE THIS DOC!!!!
76+
* @param puk The public key with which the server encrypt the message
77+
* @param hash UPDATE DOC!!!
78+
* **/
79+
public Auth(String ip, int port, String puk, String hash, int len, String proto) throws TFAuthErrors
80+
{
81+
this.IP = ip;
82+
this.PORT = port;
83+
this.PROTO = proto;
84+
this.LEN = len;
85+
this.PUK = puk;
86+
this.HASH = hash;
87+
init();
88+
}
89+
90+
// Private Methods
91+
/**
92+
* Initialize the class, for overloading the constructors and not need to rewrite the code,
93+
* I put this in a separate function...
94+
*/
95+
private void init() throws TFAuthErrors{
96+
crypto = new TFCrypto();
97+
AuthCallback extendedCallback = new AuthCallback();
98+
if (extended == null){
99+
extended = new ExtendedSub1(IP, PORT, PUK,
100+
HASH, LEN, PROTO, extendedCallback);
101+
}else {
102+
extended.setProtoHandler(extendedCallback);
103+
}
104+
if (extended.connect().isConnect()) {
105+
new TfprotocolWrapper(extended.getConHandler()).mkdirCommand(PATH);
106+
} else {
107+
throw new TFAuthErrors("Cannot connect succesfully to " + this.IP);
108+
}
109+
}
110+
111+
public ExtendedSub1 getProtocol(){
112+
return this.extended;
113+
}
114+
// Public Methods
115+
/**
116+
* The public method to access to the register auth action...
117+
* */
118+
public void register(Model rm) throws TFAuthErrors{
119+
if (currentState != States.Idle) throw new TFAuthErrors("Auth instance is not idle," +
120+
"please check you are not doing some other stuffs");
121+
if (!extended.isConnect()) {
122+
throw new TFAuthErrors("You cant register while you are offline...");
123+
}
124+
if( this.user != null){
125+
throw new TFAuthErrors("You are already logged in please logout before trying to register as" +
126+
" other user...",
127+
TFAuthErrors.ErrorsKinds.AlreadyLogged.ordinal());
128+
}
129+
currentState = States.Register;
130+
crypto.genKey();
131+
TFRegister.register(rm, extended);
132+
this.user = rm;
133+
currentState = States.Idle;
134+
}
135+
136+
/**
137+
* The public method to access to the login auth action...
138+
* */
139+
public void login(Model model) throws TFAuthErrors{
140+
if (currentState != States.Idle) throw new TFAuthErrors("Auth instance is not idle," +
141+
"please check you are not doing some other stuffs");
142+
if (!extended.isConnect()) {
143+
throw new TFAuthErrors("You can not login while you are offline...");
144+
}
145+
if( this.user != null){
146+
throw new TFAuthErrors("You are already logged in please logout before trying to login again...",
147+
TFAuthErrors.ErrorsKinds.AlreadyLogged.ordinal());
148+
}
149+
150+
currentState = States.Login;
151+
TFLogin.login(model, extended);
152+
this.user = model;
153+
currentState = States.Idle;
154+
}
155+
156+
public boolean deleteUser(String username, String password) {
157+
return new TfprotocolWrapper(extended.getConHandler())
158+
.rmdirCommand(access(TFCrypto.hash(username)+TFCrypto.hash(password)+".sd"))
159+
.equals(StatusServer.OK);
160+
}
161+
162+
// Key handle it
163+
public boolean checkKey(){
164+
return !(crypto.key == null || crypto.key.equals(""));
165+
}
166+
public void setEncryptionKey(String key){
167+
crypto.key = key;
168+
}
169+
public String getEncryptionKey() throws TFAuthErrors {
170+
if (!checkKey()) crypto.genKey();
171+
return crypto.key;
172+
}
173+
174+
public Model getUser(){
175+
return this.user;
176+
}
177+
/**
178+
* Close the connection
179+
* **/
180+
public void logout() {
181+
this.extended.disconnect();
182+
this.user = null;
183+
}
184+
185+
public boolean isLogged(){
186+
return this.user != null;
187+
}
188+
189+
//Static Functions
190+
191+
/**
192+
* This function concat the path standard directory to access to the accounts...
193+
* Each account is under that directory, if you change the value of the standard directory
194+
* You will not be able to login or register no more.... (At least not of a secure way)...
195+
* */
196+
static String access(String param){
197+
return PATH + "/" +param;
198+
}
199+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package com.nerox.Auth;
2+
3+
import com.nerox.Auth.Errors.TFAuthErrors;
4+
import com.nerox.client.callbacks.IExtendedSub1Callback;
5+
import com.nerox.client.misc.StatusInfo;
6+
import com.nerox.client.misc.StatusServer;
7+
import com.nerox.client.modules.ExtendedSub1;
8+
9+
import java.io.IOException;
10+
11+
public final class AuthCallback implements IExtendedSub1Callback {
12+
private ExtendedSub1 es;
13+
public static TFAuthHandler payloadHandler;
14+
static int fd = -1;
15+
private static void setFileDescriptor(){
16+
fd = fd == -1 ? 0 : fd+1;
17+
}
18+
19+
@Override
20+
public void instanceTfProtocol(ExtendedSub1 tfprotocol) {
21+
es = tfprotocol;
22+
payloadHandler = new TFAuthHandler(tfprotocol);
23+
}
24+
25+
@Override
26+
public void responseServerCallback(StatusInfo statusInfo) {
27+
}
28+
29+
@Override
30+
public void xs1_openCallback(StatusInfo statusInfo){
31+
setFileDescriptor();
32+
if (Auth.currentState != Auth.States.Idle){
33+
if (StatusServer.OK == statusInfo.getStatus()){
34+
try {
35+
if (Auth.currentState == Auth.States.Login){
36+
this.es.xs1_readCommand(fd,payloadHandler.getDataAsBytesArray().length+3);
37+
}else if (Auth.currentState == Auth.States.Register){
38+
//Creating the payload for registered user
39+
this.es.xs1_writeCommand(fd, payloadHandler.getDataAsBytesArray());
40+
}else if (Auth.currentState == Auth.States.Handling_in){
41+
this.es.xs1_readCommand(fd,100);
42+
}else if (Auth.currentState == Auth.States.Handling_out){
43+
this.es.xs1_writeCommand(fd,payloadHandler.getDataAsBytesArray());
44+
}
45+
} catch (IOException e) {
46+
e.printStackTrace();
47+
}finally {
48+
try {
49+
this.es.xs1_closeCommand(fd);
50+
} catch (IOException ignored) {}
51+
}
52+
}else if (StatusServer.FAILED == statusInfo.getStatus()){
53+
//System.err.println("Data file couldn't be opened, auth data will not be save it ...");
54+
}
55+
}
56+
}
57+
58+
@Override
59+
public void xs1_closeCallback(StatusInfo statusInfo) {
60+
if (Auth.currentState != Auth.States.Idle){
61+
if (StatusServer.OK == statusInfo.getStatus()){
62+
fd--;
63+
//System.out.println("Data file closed successfully...");
64+
}else if (StatusServer.FAILED == statusInfo.getStatus()){
65+
//System.err.println("ERROR: Data file still open...");
66+
}
67+
}
68+
}
69+
70+
@Override
71+
public void xs1_readCallback(StatusInfo statusInfo) {
72+
if (statusInfo != null && StatusServer.OK == statusInfo.getStatus()){
73+
if (Auth.currentState != Auth.States.Idle) {
74+
try {
75+
String temp = TFCrypto.toString(statusInfo.getPayload(), "read");
76+
temp = temp.replaceAll(":",": ");
77+
payloadHandler.retrieveData(temp, true);
78+
} catch (TFAuthErrors tfAuthErrors) {
79+
tfAuthErrors.printStackTrace();
80+
}
81+
}
82+
}
83+
}
84+
85+
@Override
86+
public void xs1_writeCallback(StatusInfo statusInfo) {
87+
if (Auth.currentState != Auth.States.Idle){
88+
if (StatusServer.OK == statusInfo.getStatus()){
89+
}else if (StatusServer.FAILED == statusInfo.getStatus()){
90+
}
91+
}
92+
}
93+
}

0 commit comments

Comments
 (0)