A utility for parsing, validating, and building Common Platform Enumeration (CPE) v2.2 and v2.3 as originally defined by MITRE and maintained by NIST.
The implementation's matching deviates slightly from the official matching specification:
- matching only returns true or false as opposed to set relations (DISJOINT, SUBSET, SUPERSET, EQUAL, UNDEFINED) specified in the matching standard.
undefinedmatches are mapped to eithertrueorfalsebased on the implementors best judgment; examples:ANYwill matchNAand returntrueinstead ofundefinedANYwill matchm + wild cardsand returntrueinstead ofundefinedNAwill not matchm + wild cardsand returnfalseinstead ofundefinediwill matchm + wild cardsifimatchesm + wild cardswhenm + wild cardsis evalauted as text instead of processing thewild cards.m1 + wild cardswill matchm2 + wild cardsif the expressionm1 + wild cardsmatchesm2 + wild cardswhenm2 + wild cardsis treated as text instead of process thewild cards
<dependency>
<groupId>us.springett</groupId>
<artifactId>cpe-parser</artifactId>
<version>3.0.0</version>
</dependency>CpeBuilder builder = new CpeBuilder();
Cpe apache = builder.part(Part.APPLICATION).vendor("apache").build();
Cpe parsed = CpeParser.parse("cpe:2.3:a:apache:commons-text:1.6:*:*:*:*:*:*:*");
if (apache.matches(parsed)) {
System.out.println("Parsed CPE value is an application CPE for the vendor 'apache'");
}CPE Parser is Copyright (c) Steve Springett. All Rights Reserved.
Permission to modify and redistribute is granted under the terms of the Apache 2.0 license. See the LICENSE file for the full license.