added wifi classification and initial class
This commit is contained in:
@@ -111,6 +111,10 @@ public class QRCodeTypeService {
|
||||
// Create the QR Code Instance based on the QR Code Type & insert into the respective table
|
||||
QRCodeModel<?> qrCodeModel = qrCodeFactoryProvider.createQRCodeInstance(scannedQR);
|
||||
qrCodeModel.setDetails();
|
||||
// Get classifications based on verificationsv
|
||||
scannedQR.setResult(qrCodeModel.retrieveClassification());
|
||||
// update result category in qrcode table
|
||||
qrCodeRepository.save(scannedQR);
|
||||
|
||||
return BaseScanResponse.builder().qrcode(qrCodeModel).build();
|
||||
}
|
||||
|
||||
@@ -72,7 +72,17 @@ public class URLVerificationService {
|
||||
URLEntity urlObj = new URLEntity();
|
||||
try {
|
||||
//URL url = new URI(encodeUrl(urlString)).toURL();
|
||||
URL url = new URI(urlString).toURL();
|
||||
URL url = new URI(urlString.replace(" ", "")).toURL();
|
||||
// Check for URL encoding in path and query
|
||||
String query = parseQueryParams(url.getQuery());
|
||||
String pathEncoding = checkURLEncoding(url.getPath());
|
||||
String queryEncoding = query != null ? checkURLEncoding(query) : "";
|
||||
|
||||
// Combine encoding results
|
||||
urlObj.setUrlEncoding(pathEncoding.equals("Yes") || queryEncoding.equals("Yes") ? "Yes" : "");
|
||||
|
||||
// encode url before proceeding the rest of the checks
|
||||
url = new URI(encodeUrl(urlString)).toURL();
|
||||
String host = url.getHost();
|
||||
|
||||
// Check for deceptive URL
|
||||
@@ -91,20 +101,12 @@ public class URLVerificationService {
|
||||
|
||||
urlObj.setPath(Optional.ofNullable(url.getPath()).filter(p -> !p.isEmpty()).orElse(""));
|
||||
|
||||
String query = parseQueryParams(url.getQuery());
|
||||
urlObj.setQuery(query);
|
||||
urlObj.setQuery(parseQueryParams(url.getQuery()));
|
||||
urlObj.setFragment(Optional.ofNullable(url.getRef()).orElse(""));
|
||||
|
||||
// Check for tracking parameters
|
||||
urlObj.setTrackingDescriptions(getTrackingDescriptions(url.getQuery()));
|
||||
|
||||
// Check for URL encoding in path and query
|
||||
String pathEncoding = checkURLEncoding(url.getPath());
|
||||
String queryEncoding = query != null ? checkURLEncoding(query) : "";
|
||||
|
||||
// Combine encoding results
|
||||
urlObj.setUrlEncoding(pathEncoding.equals("Yes") || queryEncoding.equals("Yes") ? "Yes" : "");
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Error in breaking down URL: {}", e.getMessage());
|
||||
}
|
||||
@@ -266,7 +268,7 @@ public class URLVerificationService {
|
||||
|
||||
public void countAndTrackRedirects(String urlString, URLEntity details) throws IOException {
|
||||
try {
|
||||
URI uri = new URI(urlString);
|
||||
URI uri = new URI(encodeUrl(urlString));
|
||||
URL url = uri.toURL();
|
||||
List<String> redirectChain = new ArrayList<>();
|
||||
List<String> hstsHeaderList = new ArrayList<>();
|
||||
|
||||
@@ -10,6 +10,8 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.safeqr.app.constants.CommonConstants.*;
|
||||
|
||||
@Service
|
||||
public class WifiVerificationService {
|
||||
private final WifiRepository wifiRepository;
|
||||
@@ -28,4 +30,46 @@ public class WifiVerificationService {
|
||||
wifiRepository.save(wifiEntity);
|
||||
}
|
||||
|
||||
public void parseWifiString(WifiEntity wifiEntity, String wifiString) {
|
||||
wifiString = wifiString.substring(5);
|
||||
// Split the string by semicolons
|
||||
String[] parts = wifiString.split(";");
|
||||
|
||||
for (String part : parts) {
|
||||
if (part.startsWith("T:")) {
|
||||
wifiEntity.setEncryption(part.substring(2));
|
||||
} else if (part.startsWith("S:")) {
|
||||
wifiEntity.setSsid(part.substring(2));
|
||||
} else if (part.startsWith("P:")) {
|
||||
wifiEntity.setPassword(part.substring(2));
|
||||
} else if (part.startsWith("H:")) {
|
||||
wifiEntity.setHidden(Boolean.parseBoolean(part.substring(2)));
|
||||
}
|
||||
}
|
||||
|
||||
// Unescape special characters in SSID and password
|
||||
wifiEntity.setSsid(unescapeString(wifiEntity.getSsid()));
|
||||
wifiEntity.setPassword(unescapeString(wifiEntity.getPassword()));
|
||||
}
|
||||
|
||||
private String unescapeString(String input) {
|
||||
return input.replace("\\:", ":")
|
||||
.replace("\\;", ";")
|
||||
.replace("\\,", ",")
|
||||
.replace("\\\\", "\\");
|
||||
}
|
||||
|
||||
public String getClassification(String encryptionType) {
|
||||
if (encryptionType.equalsIgnoreCase("WPA") ||
|
||||
encryptionType.equalsIgnoreCase("WPA2") ||
|
||||
encryptionType.equalsIgnoreCase("WPA3")) {
|
||||
return CLASSIFY_SAFE;
|
||||
} else if (encryptionType.equalsIgnoreCase("WEP")) {
|
||||
return CLASSIFY_WARNING;
|
||||
} else if (encryptionType.equalsIgnoreCase("nopass")) {
|
||||
return CLASSIFY_UNSAFE;
|
||||
} else {
|
||||
return CLASSIFY_UNKNOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user